Deploy Hetzner PROD #36
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: Deploy Hetzner PROD | |
on: | |
push: | |
branches: | |
- hetzner | |
workflow_dispatch: | |
inputs: | |
infra_deploy: | |
description: Infra deploy | |
type: boolean | |
required: false | |
default: false | |
apps_deploy: | |
description: Apps deploy | |
type: boolean | |
required: false | |
default: false | |
concurrency: | |
group: deploy-hetzner-${{ github.ref }} | |
cancel-in-progress: false | |
env: | |
ANSIBLE_FORCE_COLOR: true | |
TARGET_PLATFORMS: linux/arm64 | |
SEGMENT_DOWNLOAD_TIMEOUT_MINS: 2 | |
HCLOUD_KEY: ${{ secrets.HCLOUD_KEY }} | |
REGISTRY_PASSWORD: ${{ secrets.REGISTRY_PASSWORD }} | |
REGISTRY_USERNAME: ${{ secrets.REGISTRY_USERNAME }} | |
WEBSITE_DOMAIN: ${{ secrets.WEBSITE_DOMAIN }} | |
jobs: | |
changes: | |
runs-on: ubuntu-latest | |
if: github.event.inputs.apps_deploy != 'true' && github.event.inputs.infra_deploy != 'true' | |
outputs: | |
apps: ${{ steps.changes.outputs.apps }} | |
infra: ${{ steps.changes.outputs.infra }} | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- uses: dorny/paths-filter@v2 | |
id: changes | |
with: | |
base: ${{ github.ref }} | |
filters: | | |
infra: | |
- 'hetzner/**' | |
- '.github/**' | |
apps: | |
- 'apps/**' | |
- 'packages/**' | |
configure: | |
runs-on: ubuntu-latest | |
needs: [changes] | |
if: | | |
always() | |
&& !cancelled() | |
&& (needs.changes.outputs.infra == 'true' || github.event.inputs.infra_deploy == 'true') | |
timeout-minutes: 35 | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- name: Export SSH keys | |
working-directory: ./infra | |
run: | | |
mkdir -p ./keys/ansible | |
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ./keys/ansible/id_rsa | |
chmod 400 ./keys/ansible/id_rsa | |
ssh-keygen -y -f ./keys/ansible/id_rsa > ./keys/ansible/id_rsa.pub | |
- uses: actions/setup-python@v4 | |
with: | |
python-version: "3.9" | |
cache: "pip" | |
- name: Install python3 deps | |
run: pip3 install -r requirements.txt | |
- name: Run ansible galaxy install | |
working-directory: ./infra | |
run: ansible-galaxy install -r ./requirements.yml | |
- name: Run configure playbook | |
working-directory: ./infra | |
run: ansible-playbook ./configure.yml | |
deploy-docker-images: | |
runs-on: ubuntu-latest | |
needs: [changes, configure] | |
if: | | |
always() | |
&& !cancelled() | |
&& (needs.changes.outputs.apps == 'true' || github.event.inputs.apps_deploy == 'true') | |
&& (needs.configure.result == 'success' || needs.configure.result == 'skipped') | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- uses: oven-sh/setup-bun@v1 | |
with: | |
bun-version: latest | |
- name: Install dependencies | |
run: bun install | |
- name: Turbo Cache | |
uses: actions/cache@v3 | |
with: | |
path: .turbo | |
key: turbo-${{ github.job }}-${{ github.ref_name }}-${{ github.sha }} | |
restore-keys: | | |
turbo-${{ github.job }}-${{ github.ref_name }}- | |
- name: Build packages | |
run: bunx turbo build | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v2 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
- name: Login to registry | |
uses: docker/login-action@v2 | |
with: | |
registry: ${{ secrets.WEBSITE_DOMAIN }} | |
username: ${{ secrets.REGISTRY_USERNAME }} | |
password: ${{ secrets.REGISTRY_PASSWORD }} | |
- name: Cache Docker layers | |
uses: actions/cache@v3 | |
with: | |
path: /tmp/.buildx-cache | |
key: buildx-${{ github.job }}-${{ github.ref_name }}-${{ github.sha }} | |
restore-keys: | | |
buildx-${{ github.job }}-${{ github.ref_name }}- | |
- name: Push frontend | |
uses: docker/build-push-action@v4 | |
with: | |
context: apps/frontend | |
push: true | |
tags: ${{ secrets.WEBSITE_DOMAIN }}/app-frontend:latest | |
platforms: ${{ env.TARGET_PLATFORMS }} | |
cache-from: type=local,src=/tmp/.buildx-cache | |
cache-to: type=local,dest=/tmp/.buildx-cache-new | |
- name: Move cache | |
run: | | |
rm -rf /tmp/.buildx-cache | |
mv /tmp/.buildx-cache-new /tmp/.buildx-cache |