Skip to content

this is getting to be pain in the arse #13

this is getting to be pain in the arse

this is getting to be pain in the arse #13

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@v2
- name: Set up Go
uses: actions/setup-go@v2
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
GOOS=linux GOARCH=amd64 CGO_ENABLED=1 CC=x86_64-linux-gnu-gcc go build -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: 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/main
- 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 cp /home/seanwelch/bin/main /home/seanwelch/server/bin/main
echo ${{ secrets.SUDO_PASSWORD }} | sudo -S systemctl start farmec.service
echo ${{ secrets.SUDO_PASSWORD }} | sudo -S systemctl restart nginx