Skip to content

Deploy on develop

Deploy on develop #111

Workflow file for this run

name: Deploy
run-name: Deploy on ${{ github.ref_name }}
on:
push:
branches:
- master
- develop
concurrency:
group: build-${{ github.ref_name }}
cancel-in-progress: true
env:
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
DOCKERHUB_PASSWORD: ${{ secrets.DOCKERHUB_PASSWORD }}
API_URL: ${{ github.ref_name == 'master' && secrets.API_URL_MASTER || secrets.API_URL_DEVELOP }}
FRONTEND_IMAGE: ${{ secrets.DOCKERHUB_USERNAME }}/wink-official-frontend:${{ github.ref_name }}
BACKEND_IMAGE: ${{ secrets.DOCKERHUB_USERNAME }}/wink-official-backend:${{ github.ref_name }}
SSH_HOST: ${{ github.ref_name == 'master' && secrets.SSH_MASTER_HOST || secrets.SSH_DEVELOP_HOST }}
SSH_USERNAME: ${{ github.ref_name == 'master' && secrets.SSH_MASTER_USERNAME || secrets.SSH_DEVELOP_USERNAME }}
SSH_KEY: ${{ github.ref_name == 'master' && secrets.SSH_MASTER_KEY || secrets.SSH_DEVELOP_KEY }}
jobs:
build-frontend-amd64:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: ${{ github.ref_name }}
submodules: 'recursive'
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ env.DOCKERHUB_USERNAME }}
password: ${{ env.DOCKERHUB_PASSWORD }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Write .env
run: echo "API_URL=${API_URL}" > frontend/.env
- name: Build frontend (amd64)
uses: docker/build-push-action@v6
with:
push: true
context: frontend
platforms: linux/amd64
provenance: false
tags: ${{ env.FRONTEND_IMAGE }}-amd64
cache-from: type=registry,ref=${{ env.FRONTEND_IMAGE }}-amd64-cache
cache-to: type=registry,ref=${{ env.FRONTEND_IMAGE }}-amd64-cache
build-frontend-arm64:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: ${{ github.ref_name }}
submodules: 'recursive'
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ env.DOCKERHUB_USERNAME }}
password: ${{ env.DOCKERHUB_PASSWORD }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Write .env
run: echo "API_URL=${API_URL}" > frontend/.env
- name: Build frontend (arm64)
uses: docker/build-push-action@v6
with:
push: true
context: frontend
platforms: linux/arm64
tags: ${{ env.FRONTEND_IMAGE }}-arm64
provenance: false
cache-from: type=registry,ref=${{ env.FRONTEND_IMAGE }}-arm64-cache
cache-to: type=registry,ref=${{ env.FRONTEND_IMAGE }}-arm64-cache
build-backend-amd64:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: ${{ github.ref_name }}
submodules: 'recursive'
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ env.DOCKERHUB_USERNAME }}
password: ${{ env.DOCKERHUB_PASSWORD }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build backend (amd64)
uses: docker/build-push-action@v6
with:
push: true
context: backend
platforms: linux/amd64
provenance: false
tags: ${{ env.BACKEND_IMAGE }}-amd64
cache-from: type=registry,ref=${{ env.BACKEND_IMAGE }}-amd64-cache
cache-to: type=registry,ref=${{ env.BACKEND_IMAGE }}-amd64-cache
build-backend-arm64:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: ${{ github.ref_name }}
submodules: 'recursive'
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ env.DOCKERHUB_USERNAME }}
password: ${{ env.DOCKERHUB_PASSWORD }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build backend (arm64)
uses: docker/build-push-action@v6
with:
push: true
context: backend
platforms: linux/arm64
provenance: false
tags: ${{ env.BACKEND_IMAGE }}-arm64
cache-from: type=registry,ref=${{ env.BACKEND_IMAGE }}-arm64-cache
cache-to: type=registry,ref=${{ env.BACKEND_IMAGE }}-arm64-cache
merge-frontend:
runs-on: ubuntu-latest
needs: [ build-frontend-amd64, build-frontend-arm64 ]
steps:
- name: Login to Docker Hub
run: echo "${{ env.DOCKERHUB_PASSWORD }}" | docker login -u ${{ env.DOCKERHUB_USERNAME }} --password-stdin
- name: Pull Frontend Image
run: |
docker pull --platform linux/amd64 ${{ env.FRONTEND_IMAGE }}-amd64
docker pull --platform linux/arm64 ${{ env.FRONTEND_IMAGE }}-arm64
- name: Merge Frontend Image
run: |
docker manifest create ${{ env.FRONTEND_IMAGE }} ${{ env.FRONTEND_IMAGE }}-amd64 ${{ env.FRONTEND_IMAGE }}-arm64
docker manifest annotate ${{ env.FRONTEND_IMAGE }} ${{ env.FRONTEND_IMAGE }}-amd64 --os linux --arch amd64
docker manifest annotate ${{ env.FRONTEND_IMAGE }} ${{ env.FRONTEND_IMAGE }}-arm64 --os linux --arch arm64
- name: Push Frontend Image
run: docker manifest push ${{ env.FRONTEND_IMAGE }}
merge-backend:
runs-on: ubuntu-latest
needs: [ build-backend-amd64, build-backend-arm64 ]
steps:
- name: Login to Docker Hub
run: echo "${{ env.DOCKERHUB_PASSWORD }}" | docker login -u ${{ env.DOCKERHUB_USERNAME }} --password-stdin
- name: Pull Backend Image
run: |
docker pull --platform linux/amd64 ${{ env.BACKEND_IMAGE }}-amd64
docker pull --platform linux/arm64 ${{ env.BACKEND_IMAGE }}-arm64
- name: Merge Backend Image
run: |
docker manifest create ${{ env.BACKEND_IMAGE }} ${{ env.BACKEND_IMAGE }}-amd64 ${{ env.BACKEND_IMAGE }}-arm64
docker manifest annotate ${{ env.BACKEND_IMAGE }} ${{ env.BACKEND_IMAGE }}-amd64 --os linux --arch amd64
docker manifest annotate ${{ env.BACKEND_IMAGE }} ${{ env.BACKEND_IMAGE }}-arm64 --os linux --arch arm64
- name: Push Backend Image
run: docker manifest push ${{ env.BACKEND_IMAGE }}
deploy:
runs-on: ubuntu-latest
needs: [ build-frontend-amd64, build-backend-amd64 ]
steps:
- name: Deploy
uses: appleboy/ssh-action@v1.0.3
with:
host: ${{ env.SSH_HOST }}
username: ${{ env.SSH_USERNAME }}
key: ${{ env.SSH_KEY }}
script: |
cd wink-official-deploy
docker compose pull
docker compose up -d