[#13] CICD 개선 #44
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: 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 | |
- name: Login to Docker Hub | |
uses: docker/login-action@v2 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_PASSWORD }} | |
- name: Set BE .env | |
run: | | |
echo "MONGO_URI=${{ secrets.DEPLOY_MONGO_URI }}" > apps/server/.env | |
echo "IS_LOCAL=false" >> apps/server/.env | |
echo "SERVER_CORS_ACCEPT=${{ secrets.DEPLOY_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_STATIC_STORAGE_URL=${{ secrets.VITE_STATIC_STORAGE_URL }}" >> apps/client/.env | |
- name: Set Nginx SSL files | |
run: | | |
mkdir -p apps/client/ssl | |
echo "${{ secrets.SSL_FULLCHAIN }}" > apps/client/ssl/fullchain.pem | |
echo "${{ secrets.SSL_PRIVKEY }}" > apps/client/ssl/privkey.pem | |
- name: Build and Push Base Image | |
run: | | |
docker buildx build \ | |
--file Dockerfile.base \ | |
--tag ${{ secrets.DOCKERHUB_USERNAME }}/base-image:latest \ | |
--cache-from=type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/base-image:cache \ | |
--cache-to=type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/base-image:cache,mode=max \ | |
--push . | |
docker tag ${{ secrets.DOCKERHUB_USERNAME }}/base-image:latest base-image | |
- name: Build and Push Frontend Image | |
run: | | |
docker buildx build \ | |
--file apps/client/Dockerfile \ | |
--tag ${{ secrets.DOCKERHUB_USERNAME }}/boolock_client_test:latest \ | |
--cache-from=type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/boolock_client_test:cache \ | |
--cache-to=type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/boolock_client_test:cache,mode=max \ | |
--push . | |
- name: Build and Push Backend Image | |
run: | | |
docker buildx build \ | |
--file apps/server/Dockerfile \ | |
--tag ${{ secrets.DOCKERHUB_USERNAME }}/boolock_server_test:latest \ | |
--cache-from=type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/boolock_server_test:cache \ | |
--cache-to=type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/boolock_server_test:cache,mode=max \ | |
--push . | |
deploy: | |
needs: build | |
runs-on: ubuntu-latest | |
steps: | |
- name: Deploy with docker | |
uses: appleboy/[email protected] | |
with: | |
host: ${{ secrets.SSH_HOST }} | |
username: ${{ secrets.SSH_USER }} | |
password: ${{ secrets.SSH_PASSWORD }} | |
port: ${{ secrets.SSH_PORT }} | |
script: | | |
cd boolock/refactor-web31-BooLock | |
git fetch origin | |
git checkout refactor/13 | |
git pull origin refactor/13 | |
echo "DOCKERHUB_USERNAME=${{ secrets.DOCKERHUB_USERNAME }}" > .env | |
echo "${{ secrets.DOCKERHUB_ACCESS_TOKEN }}" | docker login -u ${{ secrets.DOCKERHUB_USERNAME }} --password-stdin | |
sudo docker compose pull | |
sudo docker compose down | |
sudo docker compose up -d | |
sudo docker image prune -f |