Skip to content

Commit

Permalink
Added GH Actions
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelveter committed Aug 22, 2024
1 parent 3574f6f commit 6323cc3
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 7 deletions.
45 changes: 45 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Deploy

on:
push:
branches:
- main

jobs:
deploy:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Install Docker Compose
run: |
sudo apt-get update
sudo apt-get install -y docker-compose
- name: Build Docker image
run: docker-compose build

- name: List Docker images
run: docker images

- name: Tag Docker image
run: docker tag pavelveter/urlshortener latest

- name: Login to Docker Hub
run: |
echo "${{ secrets.DOCKER_PASSWORD }}" | docker login -u "${{ secrets.DOCKER_USERNAME }}" --password-stdin
- name: Push Docker image to Docker Hub
run: docker push pavelveter/urlshortener:latest

- name: Deploy to vps
run: |
echo "${{ secrets.SSH_PRIVATE_KEY }}" > private_key.pem
chmod 600 private_key.pem
ssh -i private_key.pem -p ${{ secrets.VPS_PORT }} -o StrictHostKeyChecking=no ${{ secrets.VPS_USER }}@${{ secrets.VPS_HOST }} "cd /home/good/shortener && docker-compose pull && docker-compose up -d"
rm private_key.pem
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
config.ini
urls.txt
config.ini
3 changes: 1 addition & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,5 @@ RUN go build -o app main.go
FROM alpine:latest
WORKDIR /app
COPY --from=builder /app/app /app/
COPY config.ini urls.txt ./
EXPOSE 8081
CMD ["./app"]
CMD ["./app"]
5 changes: 2 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
version: '2.2'

services:
url_shortener:
urlshortener:
build:
context: .
dockerfile: Dockerfile
image: pavelveter/urlshortener:latest
ports:
- '8081:8081'
volumes:
Expand Down

0 comments on commit 6323cc3

Please sign in to comment.