Skip to content

Deploy by @Magistrus #208

Deploy by @Magistrus

Deploy by @Magistrus #208

Workflow file for this run

name: Deploy
run-name: Deploy by @${{ github.actor }}
on:
push:
branches:
- main
- dev
pull_request:
types:
- opened
- reopened
- synchronize
- ready_for_review
- review_requested
- auto_merge_enabled
workflow_dispatch:
env:
REGISTRY: ghcr.io
jobs:
build:
name: Build docker image
runs-on: ubuntu-latest
if: ${{ github.head_ref != 'main' && github.head_ref != 'dev' }}
concurrency:
group: build-${{ github.ref_name }}
cancel-in-progress: true
permissions:
contents: read
packages: write
attestations: write
id-token: write
steps:
- uses: actions/checkout@v4
- uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ github.token }}
- uses: docker/metadata-action@v5
id: meta
with:
images: ${{ env.REGISTRY }}/${{ github.repository }}
tags: |
type=ref,event=pr,enbled=${{ github.event_name == 'pull_request' }}
type=ref,event=branch,enbled=${{ github.event_name != 'pull_request' }}
type=raw,value=latest,enabled=${{ github.ref_name == 'main' }}
labels: |
org.opencontainers.image.title=${{ github.repository }}
org.opencontainers.image.vendor=${{ github.repository_owner }}
org.opencontainers.image.created=${{ github.event.repository.updated_at }}
org.opencontainers.image.source=${{ github.server_url }}/${{ github.repository }}
org.opencontainers.image.revision=${{ github.sha }}
- uses: docker/build-push-action@v6
id: push
with:
context: .
file: ./Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
- uses: actions/attest-build-provenance@v1
with:
subject-name: ${{ env.REGISTRY }}/${{ github.repository }}
subject-digest: ${{ steps.push.outputs.digest }}
push-to-registry: true
update:
name: Update Server
needs: build
runs-on: ubuntu-latest
if: ${{ github.ref_name == 'main' || github.ref_name == 'dev' }}
concurrency:
group: update-${{ github.ref_name == 'main' && 'prod' || 'dev' }}-server
cancel-in-progress: false
env:
CONFIG_FILE: ${{ secrets.TMWEB_SSH_PATH }}/${{ github.ref_name == 'main' && 'prod' || 'dev' }}/core/compose.core.yaml
steps:
- uses: appleboy/ssh-action@master
with:
host: ${{secrets.TMWEB_SSH_HOST}}
username: ${{secrets.TMWEB_SSH_USER}}
key: ${{secrets.TMWEB_SSH_KEY}}
port: ${{secrets.TMWEB_SSH_PORT}}
script: |
docker compose -f ${{ env.CONFIG_FILE }} pull api && \
docker compose -f ${{ env.CONFIG_FILE }} build api && \
docker compose -f ${{ env.CONFIG_FILE }} up api \
--no-deps \
--detach
docker rmi $(docker images --filter "dangling=true" -q --no-trunc) &