Skip to content

Add few more tasks; also deploy from local #56

Add few more tasks; also deploy from local

Add few more tasks; also deploy from local #56

Workflow file for this run

name: Deploy
on:
push:
branches:
- main
pull_request:
jobs:
lint:
name: Run Linter
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: stable
- name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: v1.60
tests:
name: Run Tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: stable
- name: Install dependencies
run: go mod download
- name: Run unit tests
run: go test -v ./...
deploy:
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
needs: [lint, tests]
name: Deploy to server
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: docker/setup-buildx-action@v1
- name: Build Docker image
run: docker build -t trackme-builder .
- name: Extract binary from Docker container
run: |
docker create --name extract trackme-builder
docker cp extract:/app/trackme ./trackme
docker rm extract
- name: Copy binary, assets and templates to server
uses: appleboy/[email protected]
with:
host: ${{ secrets.SERVER_IP }}
username: ${{ secrets.SERVER_USER }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
port: 22
source: "trackme,web"
target: "~/track-me-temp/"
- name: Restart server with new binary
uses: appleboy/[email protected]
with:
host: ${{ secrets.SERVER_IP }}
username: ${{ secrets.SERVER_USER }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
port: 22
script: |
~/track-me-temp/trackme --ping
if [ $? -eq 0 ]; then
echo "New binary test passed. Proceeding with deployment."
sudo systemctl stop trackme.service
mv ~/track-me-temp/trackme /root/track-me/trackme
rsync -av ~/track-me-temp/web/assets/* /root/track-me/web/assets
rsync -av ~/track-me-temp/web/templates/* /root/track-me/web/templates
sudo systemctl start trackme.service
else
echo "New binary test failed. Aborting deployment."
exit 1
fi
rm -rf ~/track-me-temp/*