update routes /api #45
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: Go Build, Test, and Deploy | |
on: | |
push: | |
branches: | |
- main | |
pull_request: | |
branches: | |
- main | |
jobs: | |
build-and-test: | |
name: Build and Test | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Set up Go | |
uses: actions/setup-go@v2 | |
with: | |
go-version: 1.20.4 | |
- name: Install Make | |
run: | | |
sudo apt update | |
sudo apt install -y make | |
- name: Build | |
run: make build | |
- name: Install dependencies | |
run: go mod tidy | |
- name: Run tests | |
run: go test -v ./... | |
deploy-to-ec2: | |
name: Deploy to EC2 | |
needs: build-and-test | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout the files | |
uses: actions/checkout@v2 | |
- name: Deploy to Server | |
uses: easingthemes/ssh-deploy@main | |
env: | |
SSH_PRIVATE_KEY: ${{ secrets.EC2_SSH_KEY }} | |
REMOTE_HOST: ${{ secrets.HOST_DNS }} | |
REMOTE_USER: ${{ secrets.USERNAME }} | |
TARGET: ${{ secrets.TARGET_DIR }} | |
- name: Connect to EC2 instance | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.HOST_DNS }} | |
username: ubuntu | |
key: ${{ secrets.EC2_SSH_KEY }} | |
script: | | |
cd any-fashion-gin-clean-code | |
git pull | |
sudo docker-compose down # Stop running containers | |
sudo docker-compose build | |
sudo docker-compose-up # Recreate and start containers |