Skip to content

Commit

Permalink
ci: workflow 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
son-daehyeon committed Aug 22, 2024
1 parent 139ba01 commit 723f502
Show file tree
Hide file tree
Showing 7 changed files with 331 additions and 161 deletions.
59 changes: 0 additions & 59 deletions .github/actions/build/action.yaml

This file was deleted.

34 changes: 0 additions & 34 deletions .github/actions/merge/action.yaml

This file was deleted.

191 changes: 140 additions & 51 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,100 +11,186 @@ 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 }}

REMOTE_ARCHITECTURE: ${{ secrets.REMOTE_ARCHITECTURE }}

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
env:
API_URL: ${{ github.ref_name == 'master' && secrets.API_URL_MASTER || secrets.API_URL_DEVELOP }}

- name: Build frontend (amd64)
uses: ./.github/actions/build
uses: docker/build-push-action@v6
with:
dockerhub_username: ${{ secrets.DOCKERHUB_USERNAME }}
dockerhub_password: ${{ secrets.DOCKERHUB_PASSWORD }}
branch: ${{ github.ref_name }}
push: true
platform: linux/amd64
type: frontend
context: frontend
platforms: linux/amd64
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: macos-latest
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
env:
API_URL: ${{ github.ref_name == 'master' && secrets.API_URL_MASTER || secrets.API_URL_DEVELOP }}

- name: Build frontend (arm64)
uses: ./.github/actions/build
uses: docker/build-push-action@v6
with:
dockerhub_username: ${{ secrets.DOCKERHUB_USERNAME }}
dockerhub_password: ${{ secrets.DOCKERHUB_PASSWORD }}
branch: ${{ github.ref_name }}
push: true
platform: linux/arm64
type: frontend
context: frontend
platforms: linux/arm64
tags: ${{ env.FRONTEND_IMAGE }}-arm64
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: ./.github/actions/build
uses: docker/build-push-action@v6
with:
dockerhub_username: ${{ secrets.DOCKERHUB_USERNAME }}
dockerhub_password: ${{ secrets.DOCKERHUB_PASSWORD }}
branch: ${{ github.ref_name }}
push: true
platform: linux/amd64
type: backend
context: backend
platforms: linux/amd64
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: macos-latest
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: ./.github/actions/build
uses: docker/build-push-action@v6
with:
dockerhub_username: ${{ secrets.DOCKERHUB_USERNAME }}
dockerhub_password: ${{ secrets.DOCKERHUB_PASSWORD }}
branch: ${{ github.ref_name }}
push: true
platform: linux/arm64
type: backend
context: backend
platforms: linux/arm64
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: Merge Backend Image
uses: ./.github/actions/merge
with:
dockerhub_username: ${{ secrets.DOCKERHUB_USERNAME }}
dockerhub_password: ${{ secrets.DOCKERHUB_PASSWORD }}
branch: ${{ github.ref_name }}
type: frontend
- 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]
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
uses: ./.github/actions/merge
with:
dockerhub_username: ${{ secrets.DOCKERHUB_USERNAME }}
dockerhub_password: ${{ secrets.DOCKERHUB_PASSWORD }}
branch: ${{ github.ref_name }}
type: backend
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 ]
env:
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 }}
steps:
- name: Pull repository
uses: appleboy/ssh-action@v1.0.3
Expand All @@ -117,13 +203,16 @@ jobs:
[ "$(git symbolic-ref --short HEAD)" != "${{ github.ref_name }}" ] && git checkout ${{ github.ref_name }}
git pull origin ${{ github.ref_name }}
- name: Run container
- name: Deploy
uses: appleboy/ssh-action@v1.0.3
env:
DOCKER_COMPOSE_FILE: docker-compose-${{ github.ref_name }}-${{ env.REMOTE_ARCHITECTURE }}.yaml
with:
host: ${{ env.SSH_HOST }}
username: ${{ env.SSH_USERNAME }}
key: ${{ env.SSH_KEY }}
script: |
cd wink-official-deploy
docker compose pull frontend backend
docker compose restart frontend backend
docker compose -f ${{ env.DOCKER_COMPOSE_FILE }} pull frontend backend
docker compose -f ${{ env.DOCKER_COMPOSE_FILE }} down
docker compose -f ${{ env.DOCKER_COMPOSE_FILE }} up -d frontend backend
19 changes: 2 additions & 17 deletions docker-compose.yaml → docker-compose-develop-amd64.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
services:
nginx:
image: nginx:latest
build:
context: backend
platforms:
- "linux/amd64"
- "linux/arm64"
container_name: nginx
restart: always
ports:
Expand All @@ -24,24 +19,14 @@ services:
- wink

frontend:
image: ioloolo/wink-official-frontend:develop
build:
context: frontend
platforms:
- "linux/amd64"
- "linux/arm64"
image: ioloolo/wink-official-frontend:develop-amd64
container_name: frontend
restart: always
networks:
- wink

backend:
image: ioloolo/wink-official-backend:develop
build:
context: frontend
platforms:
- "linux/amd64"
- "linux/arm64"
image: ioloolo/wink-official-backend:develop-amd64
container_name: backend
restart: always
volumes:
Expand Down
Loading

0 comments on commit 723f502

Please sign in to comment.