Version 0.0.4 #9
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: | |
release: | |
types: published | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.ref }} | |
cancel-in-progress: true | |
jobs: | |
build: | |
if: '!github.event.release.draft' | |
runs-on: ubuntu-latest | |
permissions: | |
packages: write | |
contents: read | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Log in to the Container registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Extract metadata (tags, labels) for Docker | |
id: meta | |
uses: docker/metadata-action@v5 | |
with: | |
images: ghcr.io/${{ github.repository }} | |
# enable the 'dev' or 'latest' tag depending on the release type | |
tags: | | |
type=pep440,pattern={{version}} | |
type=raw,value=dev,enable=${{ github.event.release.prerelease }} | |
flavor: | | |
latest=${{ !github.event.release.prerelease }} | |
- name: Build and push | |
uses: docker/build-push-action@v5 | |
with: | |
context: . | |
push: true | |
platforms: 'linux/amd64,linux/arm64' | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} | |
cache-from: type=registry,ref=ghcr.io/${{ github.repository }}:dev | |
cache-to: type=inline | |
outputs: | |
tag: ${{ steps.meta.outputs.version }} | |
tags: ${{ steps.meta.outputs.tags }} | |
deploy: | |
if: '!github.event.release.draft' | |
runs-on: ubuntu-latest | |
needs: build | |
permissions: | |
contents: read | |
env: | |
current: 'ghcr.io/${{ github.repository }}:${{ needs.build.outputs.tag }}' | |
steps: | |
- name: Log in to the Container registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Setup SSH keys | |
env: | |
SSH_AUTH_SOCK: /tmp/ssh_agent.sock | |
run: | | |
ssh-agent -a $SSH_AUTH_SOCK > /dev/null | |
ssh-add - <<< "${{ secrets.SSH_PRIVATE_DEPLOY_KEY }}" | |
mkdir -p ~/.ssh | |
echo "${{ secrets.DEPLOY_HOST_KEY }}" >> ~/.ssh/known_hosts | |
- name: Deploy to production | |
if: '!github.event.release.prerelease' | |
env: | |
DOCKER_HOST: 'ssh://${{ secrets.DEPLOY_DOCKER_USER }}@${{ secrets.DEPLOY_DOCKER_HOST }}' | |
SSH_AUTH_SOCK: /tmp/ssh_agent.sock | |
run: | | |
docker service update apecs_app --with-registry-auth --image="${{ env.current }}" | |
docker service update apecs_worker --with-registry-auth --image="${{ env.current }}" |