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: ⛵️ Push On Develop Branch Workflow | |
on: | |
push: | |
branches: | |
- "develop" | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} | |
cancel-in-progress: true | |
env: | |
REGISTRY_IMAGE: antoinezanardi/werewolves-assistant-api | |
jobs: | |
upload-to-docker-hub: | |
name: Upload image with develop tag to Docker Hub 🐳 | |
runs-on: ubuntu-latest | |
strategy: | |
fail-fast: false | |
matrix: | |
platform: | |
- linux/amd64 | |
- linux/arm64 | |
steps: | |
- name: Checkout GitHub repository 📡 | |
uses: actions/checkout@v4 | |
- name: Log in to Docker Hub 🔐 | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKER_HUB_USERNAME }} | |
password: ${{ secrets.DOCKER_HUB_PASSWORD }} | |
- name: Set up QEMU 🏗️ | |
uses: docker/setup-qemu-action@v3 | |
- name: Set up Docker Buildx 🏗️ | |
uses: docker/setup-buildx-action@v3 | |
- name: Docker meta 📦 | |
id: meta | |
uses: docker/metadata-action@v5 | |
with: | |
images: ${{ env.REGISTRY_IMAGE }} | |
tags: ${{ env.REGISTRY_IMAGE }}:develop | |
- name: Build and push image by digest 🐳 | |
id: build | |
uses: docker/build-push-action@v6 | |
with: | |
context: . | |
file: ./Dockerfile | |
platforms: ${{ matrix.platform }} | |
labels: ${{ steps.meta.outputs.labels }} | |
outputs: type=image,name=${{ env.REGISTRY_IMAGE }},push-by-digest=true,push=true | |
- name: Export digest 📦 | |
run: | | |
mkdir -p /tmp/digests | |
echo "${{ steps.build.outputs.digest }}" > "/tmp/digests/${{ matrix.platform }}-digest.txt" | |
- name: Upload digest 📦 | |
uses: actions/upload-artifact@v4 | |
with: | |
name: digests-${{ matrix.platform }} | |
path: /tmp/digests/${{ matrix.platform }}-digest.txt | |
merge-images-into-manifest-list: | |
name: Merge images into a manifest list 🗂️ | |
runs-on: ubuntu-latest | |
needs: upload-to-docker-hub | |
steps: | |
- name: Download digests 📩 | |
uses: actions/download-artifact@v4 | |
with: | |
name: digests | |
path: /tmp/digests | |
- name: Set up Docker Buildx 🏗️ | |
uses: docker/setup-buildx-action@v3 | |
- name: Docker meta 📦 | |
id: meta | |
uses: docker/metadata-action@v5 | |
with: | |
images: ${{ env.REGISTRY_IMAGE }} | |
tags: ${{ env.REGISTRY_IMAGE }}:develop | |
- name: Log in to Docker Hub 🔐 | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKER_HUB_USERNAME }} | |
password: ${{ secrets.DOCKER_HUB_PASSWORD }} | |
- name: Create manifest list and push 📦 | |
run: | | |
docker buildx imagetools create --tag "${{ env.REGISTRY_IMAGE }}:develop" \ | |
$(cat /tmp/digests/*-digest.txt | tr '\n' ' ') | |
- name: Inspect manifest list 🕵️ | |
run: | | |
docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}:develop | |
deploy-to-preproduction: | |
name: Deploy to preproduction server 🚀 | |
runs-on: ubuntu-latest | |
needs: merge-images-into-manifest-list | |
steps: | |
- name: Deploy to preproduction server 🚀 | |
env: | |
SSH_PRIVATE_KEY: ${{ secrets.PREPRODUCTION_SERVER_SSH_PRIVATE_KEY }} | |
SSH_USER: ${{ secrets.PREPRODUCTION_SERVER_SSH_USER }} | |
SSH_SERVER_IP: ${{ secrets.PREPRODUCTION_SERVER_SSH_ADDRESS }} | |
UPDATE_SCRIPT_FULL_PATH: ${{ secrets.PREPRODUCTION_UPDATE_SCRIPT_FULL_PATH }} | |
run: | | |
eval $(ssh-agent -s) | |
echo "$SSH_PRIVATE_KEY" | ssh-add - | |
ssh -o StrictHostKeyChecking=no $SSH_USER@$SSH_SERVER_IP << EOF | |
$UPDATE_SCRIPT_FULL_PATH | |
EOF |