Skip to content

quick fix

quick fix #25

Workflow file for this run

name: Deploy Go Application
on:
push:
branches:
- main
paths:
- server/**
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: '1.22'
- name: Install dependencies for CGO
run: |
sudo apt-get update
sudo apt-get install -y gcc libc6-dev
- name: Build Go binary with verbose output
run: |
cd server
CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build -v -o main
env:
CGO_ENABLED: '1'
- name: Upload artifact
uses: actions/upload-artifact@v2
with:
name: go-binary
path: server/main
deploy:
runs-on: ubuntu-latest
needs: build
steps:
- name: Download artifact
uses: actions/download-artifact@v2
with:
name: go-binary
- name: Remove existing file on EC2
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.EC2_HOST }}
username: ${{ secrets.EC2_USER }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
port: ${{ secrets.SSH_PORT }}
script: |
echo ${{ secrets.SUDO_PASSWORD }} | sudo -S rm -f /home/seanwelch/bin/main || true
- name: Copy files to EC2
uses: appleboy/scp-action@master
with:
host: ${{ secrets.EC2_HOST }}
username: ${{ secrets.EC2_USER }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
port: ${{ secrets.SSH_PORT }}
source: main
target: /home/seanwelch/bin/
- name: Deploy and restart service
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.EC2_HOST }}
username: ${{ secrets.EC2_USER }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
port: ${{ secrets.SSH_PORT }}
script: |
echo ${{ secrets.SUDO_PASSWORD }} | sudo -S systemctl stop farmec.service
sudo rm -f /home/seanwelch/server/bin/main
sudo cp /home/seanwelch/bin/main /home/seanwelch/server/bin/main
sudo chmod +x /home/seanwelch/server/bin/main
echo ${{ secrets.SUDO_PASSWORD }} | sudo -S systemctl start farmec.service
echo ${{ secrets.SUDO_PASSWORD }} | sudo -S systemctl restart nginx