update packages #11
Workflow file for this run
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: | |
tags: | |
- "v*" | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Install Node packages | |
run: npm install | |
- name: Build assets | |
run: npm run build | |
env: | |
NODE_ENV: production | |
- name: Login to GitHub Container Registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Build and push Docker image | |
uses: docker/build-push-action@v5 | |
with: | |
push: true | |
context: . | |
file: Dockerfile | |
tags: ghcr.io/stratumauth/website:latest,ghcr.io/stratumauth/website:${{ github.ref_name }} | |
deploy: | |
runs-on: ubuntu-latest | |
needs: build | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Set up SSH | |
run: | | |
mkdir ~/.ssh | |
echo "${{ secrets.DEPLOY_KEY }}" > ~/.ssh/deploy.key | |
chmod 700 ~/.ssh | |
chmod 600 ~/.ssh/deploy.key | |
cat >>~/.ssh/config <<END | |
Host stratum | |
HostName ${{ secrets.DEPLOY_HOST }} | |
User ${{ secrets.DEPLOY_USER }} | |
IdentityFile ~/.ssh/deploy.key | |
StrictHostKeyChecking no | |
ControlMaster auto | |
ControlPath ~/.ssh/control-%C | |
ControlPersist yes | |
END | |
- name: Get secrets | |
uses: bitwarden/sm-action@v2 | |
with: | |
access_token: ${{ secrets.BW_ACCESS_TOKEN }} | |
secrets: | | |
8e94c49e-5fb9-4a84-b49e-b210011962d5 > FLASK_SECRET_KEY | |
404ef33c-e193-4787-8903-b210011951d5 > RECAPTCHA_PRIVATE_KEY | |
c534a2fe-3fc6-47c3-bf08-b21001192353 > MAIL_USERNAME | |
0cd8bdf2-e0b3-4988-be65-b21001193a6a > MAIL_PASSWORD | |
2b41bff7-777e-4606-bcde-b21001190c37 > MAIL_RECIPIENT | |
- name: Deploy | |
run: | | |
export DOCKER_HOST=ssh://stratum | |
echo ${{ secrets.GITHUB_TOKEN }} | docker login ghcr.io -u ${{ github.actor }} --password-stdin | |
# Deploy current tag | |
sed -i 's/stratumwebsite:latest/stratumwebsite:${{ github.ref_name }}/' compose.yaml | |
docker compose -f compose.yaml pull | |
docker compose -f compose.yaml down | |
docker compose -f compose.yaml up --no-deps -d | |
docker image prune -f | |
clean: | |
runs-on: ubuntu-latest | |
needs: deploy | |
steps: | |
- name: Delete old images | |
uses: snok/[email protected] | |
with: | |
account: user | |
token: ${{ secrets.PAT }} | |
image-names: "stratumwebsite*" | |
image-tags: "!latest v*" | |
cut-off: 2d | |
keep-n-most-recent: 3 |