copy with different approach #10
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 Deploy | |
on: | |
push: | |
branches: | |
- main | |
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.4' | |
- name: Cache Go Modules | |
uses: actions/cache@v4 | |
with: | |
path: | | |
~/.cache/go-build | |
~/.cache/pkg | |
~/.config/gotestsum | |
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} | |
restore-keys: | | |
${{ runner.os }}-go- | |
- name: Build Server | |
run: go build -o server cmd/server/server.go | |
- name: Build Scheduler | |
run: go build -o scheduler cmd/scheduler/scheduler.go | |
- name: Get absolute path of the server binary | |
id: server-path | |
run: echo "SERVER_PATH=$(realpath server)" >> $GITHUB_ENV | |
- name: Get absolute path of the scheduler binary | |
id: scheduler-path | |
run: echo "SCHEDULER_PATH=$(realpath scheduler)" >> $GITHUB_ENV | |
- name: Deploy and Start Services | |
uses: appleboy/[email protected] | |
with: | |
host: ${{ secrets.SERVER }} | |
username: ${{ secrets.USERNAME }} | |
key: ${{ secrets.SSH_PRIVATE_KEY }} | |
port: 22 | |
script: | | |
sudo scp $SERVER_PATH ubuntu@${{ secrets.SERVER }}:/usr/local/bin/ | |
sudo scp $SCHEDULER_PATH ubuntu@${{ secrets.SERVER }}:/usr/local/bin/ | |
sudo chown appuser:appuser /usr/local/bin/server | |
sudo chown appuser:appuser /usr/local/bin/scheduler | |
sudo systemctl start scheduler | |
sudo systemctl enable scheduler | |
sudo systemctl start server | |
sudo systemctl enable server |