mirror of
https://github.com/dsec-hub/dsec-discord-bot.git
synced 2026-09-22 15:53:56 +00:00
A merge to main runs the merged commit as root on the club VPS through the self-hosted runner, and this repo has no PR CI, no required review and no status check. - .github/workflows/ci.yml: fmt / clippy / build --locked / test on ubuntu-latest, contents: read, both actions pinned by commit SHA. Never the VPS. - deploy.yml: keep push to main, add workflow_dispatch, permissions contents: read, environment: production, and an if: always() step that removes the .env the deploy writes into the workspace. - .dockerignore: keep that .env, target/ and .git out of the build context. - Dockerfile: --locked on both cargo build --release lines. environment: production gates nothing until required reviewers are configured on the environment itself, and the ruleset still requires zero approving reviews. Both are owner-only and listed in the pull request. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
53 lines
1.4 KiB
YAML
53 lines
1.4 KiB
YAML
name: Docker Compose Deploy
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
# Manual re-run, for redeploying after a rollback or re-creating the
|
|
# workspace .env that the cleanup step below now removes.
|
|
workflow_dispatch:
|
|
|
|
permissions:
|
|
contents: read
|
|
|
|
jobs:
|
|
build_and_deploy:
|
|
runs-on: [self-hosted, linux]
|
|
# SEC-01: this gates nothing until required reviewers are configured on the
|
|
# "production" environment itself. See the pull request description.
|
|
environment: production
|
|
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v4
|
|
with:
|
|
clean: true
|
|
fetch-depth: 1
|
|
|
|
- name: Create environment file
|
|
working-directory: ${{ github.workspace }}
|
|
env:
|
|
DOT_ENV: ${{ secrets.DOT_ENV }}
|
|
run: |
|
|
if [ -z "$DOT_ENV" ]; then
|
|
echo "DOT_ENV secret is missing or empty."
|
|
exit 1
|
|
fi
|
|
|
|
umask 077
|
|
printf '%s\n' "$DOT_ENV" > .env
|
|
|
|
- name: Build and deploy
|
|
working-directory: ${{ github.workspace }}
|
|
run: |
|
|
sudo docker compose up -d --build --force-recreate
|
|
echo "Deployment complete."
|
|
|
|
- name: Remove environment file
|
|
if: always()
|
|
working-directory: ${{ github.workspace }}
|
|
run: rm -f .env
|
|
|
|
- name: Clean up old Docker images
|
|
run: sudo docker image prune -f
|