Skip to content

๐ŸŒ Deploy(#102): cicd ์ˆ˜์ • #128

๐ŸŒ Deploy(#102): cicd ์ˆ˜์ •

๐ŸŒ Deploy(#102): cicd ์ˆ˜์ • #128

Workflow file for this run

name: CI/CD Docker
on:
push:
branches: [develop, deploy/#102/SEO_Optimization]
env:
DOCKER_IMAGE: ghcr.io/${{ github.actor }}/react-auto-deploy
VERSION: ${{ github.sha }}
NAME: go_cicd
VITE_BASE_URL: ${{ secrets.VITE_BASE_URL }}
VITE_IMG_BASE_URL: ${{ secrets.VITE_IMG_BASE_URL }}
jobs:
# ๋นŒ๋“œ Job
build:
name: Build
runs-on: ubuntu-latest
steps:
# GitHub Repository์—์„œ Checkout
- uses: actions/checkout@v3
# Docker Buildx ์„ค์ •
- name: Set up docker buildx
id: buildx
uses: docker/setup-buildx-action@v2
# Docker ์บ์‹œ ์„ค์ •
- name: Cache docker layers
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ env.VERSION }}
restore-keys: |
${{ runner.os }}-buildx-
# GitHub Container Registry ๋กœ๊ทธ์ธ
- name: Login to ghcr
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ github.actor == 'bluetree7878' && secrets.bluetree7878_GHCR_TOKEN || secrets.rhehfl_ghcr_token }}
# Docker Build ๋ฐ Push
- name: Build and push
id: docker_build
uses: docker/build-push-action@v2
with:
builder: ${{ steps.buildx.outputs.name }}
push: true
tags: ${{ env.DOCKER_IMAGE }}:latest
build-args: |
VITE_BASE_URL=${{ secrets.VITE_BASE_URL }}
VITE_IMG_BASE_URL=${{ secrets.VITE_IMG_BASE_URL }}
# ๋ฐฐํฌ Job
deploy:
needs: build # build ํ›„์— ์‹คํ–‰๋˜๋„๋ก ์„ค์ •
name: Deploy
runs-on: [self-hosted, label-go] # AWS ./configure์—์„œ ์‚ฌ์šฉํ•  label๋ช…
steps:
# GitHub Container Registry ๋กœ๊ทธ์ธ
- name: Login to ghcr
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ github.actor == 'bluetree7878' && secrets.bluetree7878_GHCR_TOKEN || secrets.rhehfl_ghcr_token }}
# `.env` ํŒŒ์ผ ์ƒ์„ฑ
- name: Generate .env file
run: |
echo IMAGE_NAME=${{ env.DOCKER_IMAGE }} > /home/ubuntu/.env
# Docker Compose๋กœ ์„œ๋น„์Šค ๋ฐฐํฌ
- name: Docker run
run: |
if [ -n "$(docker images -f "dangling=true" -q)" ]; then
docker rmi $(docker images -f "dangling=true" -q)
fi
docker compose -f /home/ubuntu/docker-compose.yml down
docker compose -f /home/ubuntu/docker-compose.yml up -d --pull always