[#31] โCode ํ์ด๋ผ์ดํ โ ์ฝ๋ ํ์ง ๊ฐ์ #132
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: dev ci/cd action | |
on: | |
push: | |
branches: ['dev'] | |
pull_request: | |
branches: ['dev'] | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
with: | |
buildkitd-flags: --debug | |
- name: Set BE .env | |
run: | | |
echo "MONGO_URI=${{ secrets.TEST_MONGO_URI }}" > apps/server/.env | |
echo "IS_LOCAL=false" >> apps/server/.env | |
echo "SERVER_CORS_ACCEPT=${{ secrets.TEST_SERVER_CORS_ACCEPT }}" >> apps/server/.env | |
echo "S3_ACCESS_KEY=${{ secrets.S3_ACCESS_KEY }}" >> apps/server/.env | |
echo "S3_SECRET_KEY=${{ secrets.S3_SECRET_KEY }}" >> apps/server/.env | |
echo "S3_BUCKET_NAME=${{ secrets.S3_BUCKET_NAME }}" >> apps/server/.env | |
echo "NODE_ENV=production" >> apps/server/.env | |
- name: Set FE .env | |
run: | | |
echo "VITE_SERVER_URL=${{ secrets.DEPLOY_VITE_SERVER_URL }}" > apps/client/.env | |
echo "VITE_MIXPANEL_TOKEN=${{ secrets.VITE_MIXPANEL_TOKEN }}" >> apps/client/.env | |
echo "VITE_STATIC_STORAGE_URL=${{ secrets.VITE_STATIC_STORAGE_URL }}" >> apps/client/.env | |
- name: Login to Docker Hub | |
uses: docker/login-action@v2 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_ACCESS_TOKEN }} | |
- name: Build and Push Base Image | |
uses: docker/build-push-action@v4 | |
with: | |
context: . | |
file: Dockerfile.base | |
push: true | |
tags: ${{ secrets.DOCKERHUB_USERNAME }}/base-image-test:latest | |
cache-from: type=gha,scope=base-image-test | |
cache-to: type=gha,mode=max,scope=base-image-test | |
- name: Build and Push Frontend Image | |
uses: docker/build-push-action@v4 | |
with: | |
context: . | |
file: apps/client/Dockerfile.test | |
push: true | |
tags: ${{ secrets.DOCKERHUB_USERNAME }}/boolock_client_test:latest | |
cache-from: type=gha,scope=frontend-test | |
cache-to: type=gha,mode=max,scope=frontend-test | |
build-args: | | |
DOCKERHUB_USERNAME=${{ secrets.DOCKERHUB_USERNAME }} | |
TYPE=test | |
- name: Build and Push Backend Image | |
uses: docker/build-push-action@v4 | |
with: | |
context: . | |
file: apps/server/Dockerfile | |
push: true | |
tags: ${{ secrets.DOCKERHUB_USERNAME }}/boolock_server_test:latest | |
cache-from: type=gha,scope=backend-test | |
cache-to: type=gha,mode=max,scope=backend-test | |
build-args: | | |
DOCKERHUB_USERNAME=${{ secrets.DOCKERHUB_USERNAME }} | |
TYPE=test | |
deploy: | |
if: github.event_name == 'push' | |
needs: build | |
runs-on: ubuntu-latest | |
steps: | |
- name: Deploy with docker | |
uses: appleboy/[email protected] | |
with: | |
host: ${{ secrets.TEST_SSH_HOST }} | |
username: ${{ secrets.TEST_SSH_USER }} | |
password: ${{ secrets.TEST_SSH_PASSWORD }} | |
port: ${{ secrets.TEST_SSH_PORT }} | |
script: | | |
cd boolock/refactor-web31-BooLock | |
git fetch origin | |
git checkout dev | |
git pull origin dev | |
echo "DOCKERHUB_USERNAME=${{ secrets.DOCKERHUB_USERNAME }}" > .env | |
echo "${{ secrets.DOCKERHUB_ACCESS_TOKEN }}" | docker login -u ${{ secrets.DOCKERHUB_USERNAME }} --password-stdin | |
sudo docker compose -f docker-compose.test.yml pull | |
sudo docker compose -f docker-compose.test.yml up -d --force-recreate --remove-orphans |