Deploy (develop) #13
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 | |
run-name: Deploy (${{ github.ref_name }}) | |
on: | |
push: | |
branches: | |
- master | |
- develop | |
concurrency: | |
group: deploy-${{ github.ref_name }} | |
cancel-in-progress: true | |
env: | |
IMAGE_NAME: ${{ secrets.DOCKERHUB_USERNAME }}/wink-official-frontend:${{ github.ref_name }} | |
API_URL: ${{ github.ref_name == 'master' && secrets.API_MASTER_URL || secrets.API_DEVELOP_URL }} | |
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-amd64: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Login to Docker Hub | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_ACCESS_TOKEN }} | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Write .env file | |
run: | | |
echo "API_URL=${{ env.API_URL }}" > .env | |
- name: Build Image | |
uses: docker/build-push-action@v6 | |
with: | |
context: . | |
push: true | |
platforms: linux/amd64 | |
provenance: false | |
tags: ${{ env.IMAGE_NAME }}-amd64 | |
cache-from: type=registry,ref=${{ env.IMAGE_NAME }}-amd64-cache | |
cache-to: type=registry,ref=${{ env.IMAGE_NAME }}-amd64-cache | |
build-arm64: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Login to Docker Hub | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_ACCESS_TOKEN }} | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Write .env file | |
run: | | |
echo "API_URL=${{ env.API_URL }}" > .env | |
- name: Build Image | |
uses: docker/build-push-action@v6 | |
with: | |
context: . | |
push: true | |
platforms: linux/arm64 | |
tags: ${{ env.IMAGE_NAME }}-arm64 | |
provenance: false | |
cache-from: type=registry,ref=${{ env.IMAGE_NAME }}-arm64-cache | |
cache-to: type=registry,ref=${{ env.IMAGE_NAME }}-arm64-cache | |
merge-image: | |
runs-on: ubuntu-latest | |
needs: [ build-amd64, build-arm64 ] | |
steps: | |
- name: Login to Docker Hub | |
run: | | |
echo "${{ secrets.DOCKERHUB_ACCESS_TOKEN }}" | docker login -u ${{ secrets.DOCKERHUB_USERNAME }} --password-stdin | |
- name: Pull Frontend Image | |
run: | | |
docker pull --platform linux/amd64 ${{ env.IMAGE_NAME }}-amd64 | |
docker pull --platform linux/arm64 ${{ env.IMAGE_NAME }}-arm64 | |
- name: Merge Frontend Image | |
run: | | |
docker manifest create ${{ env.IMAGE_NAME }} ${{ env.IMAGE_NAME }}-amd64 ${{ env.IMAGE_NAME }}-arm64 | |
docker manifest annotate ${{ env.IMAGE_NAME }} ${{ env.IMAGE_NAME }}-amd64 --os linux --arch amd64 | |
docker manifest annotate ${{ env.IMAGE_NAME }} ${{ env.IMAGE_NAME }}-arm64 --os linux --arch arm64 | |
- name: Push Frontend Image | |
run: docker manifest push ${{ env.IMAGE_NAME }} | |
check-server: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check exists project | |
uses: appleboy/[email protected] | |
with: | |
host: ${{ env.SSH_HOST }} | |
username: ${{ env.SSH_USERNAME }} | |
key: ${{ env.SSH_KEY }} | |
script: | | |
if [ ! -d "Frontend" ]; then | |
echo "Directory "Frontend" not found" | |
exit 1 | |
fi | |
- name: Check docker compose file | |
uses: appleboy/[email protected] | |
with: | |
host: ${{ env.SSH_HOST }} | |
username: ${{ env.SSH_USERNAME }} | |
key: ${{ env.SSH_KEY }} | |
script: | | |
if [ ! -f "Frontend/docker-compose.yaml" ]; then | |
echo "File "Frontend/docker-compose.yaml" not found" | |
exit 1 | |
fi | |
deploy: | |
runs-on: ubuntu-latest | |
needs: [ check-server, build-amd64 ] | |
steps: | |
- name: Deploy | |
uses: appleboy/[email protected] | |
with: | |
host: ${{ env.SSH_HOST }} | |
username: ${{ env.SSH_USERNAME }} | |
key: ${{ env.SSH_KEY }} | |
script: | | |
cd Frontend | |
docker compose pull | |
docker compose up -d |