Skip to content

Merge pull request #62 from 100-hours-a-week/feature/deploy #54

Merge pull request #62 from 100-hours-a-week/feature/deploy

Merge pull request #62 from 100-hours-a-week/feature/deploy #54

name: Front-dev build & push docker image to ghcr and deploy
on:
push:
branches:
- dev
- feature/deploy
pull_request:
branches:
- dev
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 20
- name: Install dependencies
run: npm install
- name: Build Next.js app
run: npm run build
env:
KAKAO_API_KEY: ${{ secrets.KAKAO_API_KEY_DEV }}
KAKAO_REDIRECT_URI: ${{ secrets.KAKAO_REDIRECT_URI_DEV }}
NEXT_PUBLIC_SERVER_URL: ${{ secrets.NEXT_PUBLIC_SERVER_URL_DEV }}
NEXT_PUBLIC_SELF_URL: ${{ secrets.NEXT_PUBLIC_SELF_URL_DEV }}
NEXT_PUBLIC_BASE_URL: ${{ secrets.NEXT_PUBLIC_BASE_URL_DEV }}
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
NEXT_PUBLIC_SENTRY_DSN: ${{ secrets.NEXT_PUBLIC_SENTRY_DSN }}
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: TopazKang
password: ${{ secrets.GHCR_TOKEN }}
- name: Build Docker image
run: |
docker build \
--build-arg KAKAO_API_KEY=${{ secrets.KAKAO_API_KEY_DEV }} \
--build-arg KAKAO_REDIRECT_URI=${{ secrets.KAKAO_REDIRECT_URI_DEV }} \
--build-arg NEXT_PUBLIC_SERVER_URL=${{ secrets.NEXT_PUBLIC_SERVER_URL_DEV }} \
--build-arg NEXT_PUBLIC_SELF_URL=${{ secrets.NEXT_PUBLIC_SELF_URL_DEV }} \
--build-arg NEXT_PUBLIC_BASE_URL=${{ secrets.NEXT_PUBLIC_BASE_URL_DEV }} \
--build-arg SENTRY_AUTH_TOKEN=${{ secrets.SENTRY_AUTH_TOKEN }} \
--build-arg NEXT_PUBLIC_SENTRY_DSN=${{ secrets.NEXT_PUBLIC_SENTRY_DSN }} \
-t ghcr.io/topazkang/fe-dev:latest .
- name: Push Docker image to GHCR
run: docker push ghcr.io/topazkang/fe-dev:latest
deploy:
runs-on: ubuntu-latest
needs: build
steps:
- name: SSH and Deploy Frontend
uses: appleboy/ssh-action@v0.1.8
with:
host: ${{ secrets.EC2_HOST_DEV }}
username: ${{ secrets.EC2_USER }}
key: ${{ secrets.ARK_DEPLOY }}
port: 22
script: |
echo "${{ secrets.ENV_FILE_DEV }}" > deploy/front/.env
echo "${{ secrets.GHCR_TOKEN }}" | sudo docker login ghcr.io -u ${{ secrets.GIT_USER }} --password-stdin
cd deploy/front
sudo docker image prune -a -f
sudo docker-compose -f docker-compose.front.yaml down
sudo docker-compose -f docker-compose.front.yaml pull
sudo docker-compose -f docker-compose.front.yaml up -d