Feat/emails #23
Workflow file for this run
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 | |
on: | |
pull_request: | |
types: [closed] | |
branches: | |
- main | |
- dev | |
permissions: | |
pull-requests: read | |
checks: write | |
actions: write | |
jobs: | |
PR_Merge_label: | |
if: github.event.pull_request.merged == true | |
runs-on: ubuntu-latest | |
outputs: | |
build_nestjs: ${{ steps.PR-label-nestjs.outputs.passed }} | |
build_kotlin: ${{ steps.PR-label-kotlin.outputs.passed }} | |
steps: | |
- name: λ ν¬ μ²΄ν¬μμ | |
uses: actions/checkout@main | |
- name: PR λΌλ²¨ λ€μ€νΈ | |
id: PR-label-nestjs | |
uses: danielchabr/pr-labels-checker@master | |
with: | |
hasSome: nestjs | |
githubToken: ${{ secrets.GITHUB_TOKEN }} | |
allowFailure: true | |
- name: PR λΌλ²¨ μ½νλ¦° | |
id: PR-label-kotlin | |
uses: danielchabr/pr-labels-checker@master | |
with: | |
hasSome: kotlin | |
githubToken: ${{ secrets.GITHUB_TOKEN }} | |
allowFailure: true | |
nestjs-build: | |
runs-on: ubuntu-latest | |
needs: PR_Merge_label | |
if: needs.PR_Merge_label.outputs.build_nestjs == 'true' | |
steps: | |
- name: λ ν¬ μ²΄ν¬μμ | |
uses: actions/checkout@main | |
- name: Docker Buildx μ€μ | |
uses: docker/setup-buildx-action@master | |
- name: Docker Hub λ‘κ·ΈμΈ | |
uses: docker/login-action@master | |
with: | |
username: ${{ secrets.DOCKER_HUB_USERNAME }} | |
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} | |
- name: λΉλ λ° νΈμ | |
uses: docker/build-push-action@master | |
with: | |
context: . | |
file: ./Dockerfile.nestjs | |
push: true | |
tags: ${{ secrets.DOCKER_HUB_USERNAME }}/${{ secrets.DOCKER_HUB_REPO_BE }}:nestjs | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
nestjs-deploy: | |
runs-on: ubuntu-latest | |
needs: nestjs-build | |
steps: | |
- name: λ ν¬ μ²΄ν¬μμ | |
uses: actions/checkout@main | |
- name: .env μμ± | |
env: | |
SECRETS_JSON: ${{ toJson(secrets) }} | |
run: | | |
echo "$SECRETS_JSON" | jq -r 'to_entries | map(select(.key | startswith("ENV"))) | map("\(.key)=\(.value|tostring)") | .[]' > .env | |
- name: .env μ μ‘ | |
uses: appleboy/scp-action@master | |
with: | |
host: ${{ secrets.SSH_HOST }} | |
username: ${{ secrets.SSH_USERNAME }} | |
password: ${{ secrets.SSH_PASSWORD }} | |
port: ${{ secrets.SSH_PORT }} | |
source: .env | |
target: ${{ secrets.SERVER_PATH }}/site/${{ secrets.DOCKER_HUB_USERNAME }} | |
overwrite: true | |
- name: μλ² μ μ | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.SSH_HOST }} | |
username: ${{ secrets.SSH_USERNAME }} | |
password: ${{ secrets.SSH_PASSWORD }} | |
port: ${{ secrets.SSH_PORT }} | |
script: | | |
cd ${{ secrets.SERVER_PATH }}/site/${{ secrets.DOCKER_HUB_USERNAME }} | |
# Docker Hub λ‘κ·ΈμΈ | |
echo ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} | docker login -u ${{ secrets.DOCKER_HUB_USERNAME }} --password-stdin | |
# μ΄λ―Έμ§ νλ§ | |
docker pull ${{ secrets.DOCKER_HUB_USERNAME }}/${{ secrets.DOCKER_HUB_REPO_BE }}:nestjs | |
# μλ‘μ΄ μ΄λ―Έμ§λ₯Ό Green/Blue μ€ νλλ‘ νκ·Έ | |
if docker ps | grep eatsfinder-nestjs-blue; then | |
NEW_DEPLOYMENT="green" | |
OLD_DEPLOYMENT="blue" | |
else | |
NEW_DEPLOYMENT="blue" | |
OLD_DEPLOYMENT="green" | |
fi | |
docker-compose up -d eatsfinder-nestjs-$NEW_DEPLOYMENT | |
# μ 컨ν μ΄λκ° μμλ μκ°μ κΈ°λ€λ¦Ό | |
sleep 10 | |
# Nginx μ€μ λ³κ²½ | |
if [ "$NEW_DEPLOYMENT" == "green" ]; then | |
sed -i "s/proxy_pass http:\/\/eatsfinder-nestjs-$OLD_DEPLOYMENT:${{ secrets.ENV_NESTJS_PORT }};/proxy_pass http:\/\/eatsfinder-nestjs-$NEW_DEPLOYMENT:${{ secrets.ENV_NESTJS_PORT }};/" ${{ secrets.SERVER_PATH }}/nginx/conf.d/eatsfinder.conf | |
else | |
sed -i "s/proxy_pass http:\/\/eatsfinder-nestjs-$OLD_DEPLOYMENT:${{ secrets.ENV_NESTJS_PORT }};/proxy_pass http:\/\/eatsfinder-nestjs-$NEW_DEPLOYMENT:${{ secrets.ENV_NESTJS_PORT }};/" ${{ secrets.SERVER_PATH }}/nginx/conf.d/eatsfinder.conf | |
fi | |
# Nginx μ¬μμ | |
docker-compose -f ${{ secrets.SERVER_PATH }}/docker-compose-multi.yml up -d --force-recreate --no-deps nginx | |
# μ΄μ λ²μ μ 컨ν μ΄λ μ€μ§ λ° μ κ±° | |
docker-compose stop eatsfinder-nestjs-$OLD_DEPLOYMENT | |
docker-compose rm -f eatsfinder-nestjs-$OLD_DEPLOYMENT | |
kotlin-build: | |
runs-on: ubuntu-latest | |
needs: PR_Merge_label | |
if: needs.PR_Merge_label.outputs.build_kotlin == 'true' | |
steps: | |
- name: λ ν¬ μ²΄ν¬μμ | |
uses: actions/checkout@main | |
- name: Docker Buildx μ€μ | |
uses: docker/setup-buildx-action@master | |
- name: Docker Hub λ‘κ·ΈμΈ | |
uses: docker/login-action@master | |
with: | |
username: ${{ secrets.DOCKER_HUB_USERNAME }} | |
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} | |
- name: λΉλ λ° νΈμ | |
uses: docker/build-push-action@master | |
with: | |
context: . | |
file: ./Dockerfile.kotlin | |
push: true | |
tags: ${{ secrets.DOCKER_HUB_USERNAME }}/${{ secrets.DOCKER_HUB_REPO_BE }}:kotlin | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
kotlin-deploy: | |
runs-on: ubuntu-latest | |
needs: kotlin-build | |
steps: | |
- name: λ ν¬ μ²΄ν¬μμ | |
uses: actions/checkout@main | |
- name: .env μμ± | |
env: | |
SECRETS_JSON: ${{ toJson(secrets) }} | |
run: | | |
echo "$SECRETS_JSON" | jq -r 'to_entries | map(select(.key | startswith("ENV"))) | map("\(.key)=\(.value|tostring)") | .[]' > .env | |
- name: .env μ μ‘ | |
uses: appleboy/scp-action@master | |
with: | |
host: ${{ secrets.SSH_HOST }} | |
username: ${{ secrets.SSH_USERNAME }} | |
password: ${{ secrets.SSH_PASSWORD }} | |
port: ${{ secrets.SSH_PORT }} | |
source: .env | |
target: ${{ secrets.SERVER_PATH }}/site/${{ secrets.DOCKER_HUB_REPO_BE }} | |
overwrite: true | |
- name: μλ² μ μ | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.SSH_HOST }} | |
username: ${{ secrets.SSH_USERNAME }} | |
password: ${{ secrets.SSH_PASSWORD }} | |
port: ${{ secrets.SSH_PORT }} | |
script: | | |
cd ${{ secrets.SERVER_PATH }}/site/${{ secrets.DOCKER_HUB_USERNAME }} | |
# Docker Hub λ‘κ·ΈμΈ | |
echo ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} | docker login -u ${{ secrets.DOCKER_HUB_USERNAME }} --password-stdin | |
# μ΄λ―Έμ§ νλ§ | |
docker pull ${{ secrets.DOCKER_HUB_USERNAME }}/${{ secrets.DOCKER_HUB_REPO_BE }}:kotlin | |
# μλ‘μ΄ μ΄λ―Έμ§λ₯Ό Green/Blue μ€ νλλ‘ νκ·Έ | |
if docker ps | grep eatsfinder-kotlin-blue; then | |
NEW_DEPLOYMENT="green" | |
OLD_DEPLOYMENT="blue" | |
else | |
NEW_DEPLOYMENT="blue" | |
OLD_DEPLOYMENT="green" | |
fi | |
docker-compose up -d eatsfinder-kotlin-$NEW_DEPLOYMENT | |
# μ 컨ν μ΄λκ° μμλ μκ°μ κΈ°λ€λ¦Ό | |
sleep 10 | |
# Nginx μ€μ λ³κ²½ | |
if [ "$NEW_DEPLOYMENT" == "green" ]; then | |
sed -i "s/proxy_pass http:\/\/eatsfinder-kotlin-$OLD_DEPLOYMENT:8080;/proxy_pass http:\/\/eatsfinder-kotlin-$NEW_DEPLOYMENT:8080;/" ${{ secrets.SERVER_PATH }}/nginx/conf.d/eatsfinder.conf | |
else | |
sed -i "s/proxy_pass http:\/\/eatsfinder-kotlin-$OLD_DEPLOYMENT:8080;/proxy_pass http:\/\/eatsfinder-kotlin-$NEW_DEPLOYMENT:8080;/" ${{ secrets.SERVER_PATH }}/nginx/conf.d/eatsfinder.conf | |
fi | |
# Nginx μ¬μμ | |
docker-compose -f ${{ secrets.SERVER_PATH }}/docker-compose-multi.yml up -d --force-recreate --no-deps nginx | |
# μ΄μ λ²μ μ 컨ν μ΄λ μ€μ§ λ° μ κ±° | |
docker-compose stop eatsfinder-kotlin-$OLD_DEPLOYMENT | |
docker-compose rm -f eatsfinder-kotlin-$OLD_DEPLOYMENT |