Skip to content

update the github action #26

update the github action

update the github action #26

Workflow file for this run

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 }}/boot-back:${{ github.sha }}, ${{ secrets.DOCKER_USERNAME }}/boot-back:latest
platforms: 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
docker pull dkrest/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 || (echo "Deployment failed" && exit 1)