chore: update #30
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build and Run | |
on: | |
push: | |
branches: | |
- main | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout Repository | |
uses: actions/checkout@v3 | |
- name: Set up Go | |
uses: actions/setup-go@v4 | |
with: | |
go-version: 1.21.5 | |
- name: Build | |
run: | | |
go mod download | |
go build -v . | |
env: | |
PORT: ${{ secrets.PORT }} | |
JWT_SECRET_KEY: ${{ secrets.JWT_SECRET_KEY }} | |
deploy: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout Repository | |
uses: actions/checkout@v3 | |
- name: Set up Docker | |
uses: docker/setup-buildx-action@v2 | |
- name: Login to Docker Hub | |
uses: docker/login-action@v2 | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
- name: Build and Push Docker Image | |
uses: docker/build-push-action@v4 | |
with: | |
# context: . | |
file: ./Dockerfile | |
push: true | |
tags: ${{ secrets.DOCKER_USERNAME }}/task-manager:${{ github.sha }}, ${{ secrets.DOCKER_USERNAME }}/task-manager:latest | |
platforms: linux/amd64,linux/arm64 | |
- name: SSH into EC2 Instance and Deploy | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.EC2_HOST }} | |
username: ${{ secrets.EC2_USERNAME }} | |
key: ${{ secrets.EC2_PRIVATE_KEY }} | |
port: ${{ secrets.EC2_PORT }} | |
script: | | |
sleep 10 | |
set -e | |
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }} | |
docker pull dkrest1/task-manager:latest | |
docker stop task-manager || true | |
docker rm task-manager || true | |
docker run -d -p 9090:9090 --name task-manager dkrest1/task-manager:latest > deployment.log 2>&1 || (echo "Deployment failed" && cat deployment.log && exit 1) | |
docker ps | grep task-manager |