From 5318279c416312d69f2cac574c62996470a46d83 Mon Sep 17 00:00:00 2001 From: BYEONGRYEOL Date: Sat, 20 Jul 2024 14:27:20 +0900 Subject: [PATCH] =?UTF-8?q?Fix:=20#62=20dev=EC=97=90=20=EC=A0=81=EC=9A=A9?= =?UTF-8?q?=EB=90=98=EB=8D=98=20ci/cd=20=ED=8C=8C=EC=9D=B4=ED=94=84?= =?UTF-8?q?=EB=9D=BC=EC=9D=B8=20=EB=A1=9C=EC=A7=81=20dev=20->=20staging?= =?UTF-8?q?=EC=9C=BC=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/cicd-ec2.yml | 40 +++++++++++----------- .gitignore | 8 +++-- docker/staging/.env | 13 +++++++ docker/{dev => staging}/docker-compose.yml | 4 +-- 4 files changed, 41 insertions(+), 24 deletions(-) create mode 100644 docker/staging/.env rename docker/{dev => staging}/docker-compose.yml (86%) diff --git a/.github/workflows/cicd-ec2.yml b/.github/workflows/cicd-ec2.yml index cab57e59..31305381 100644 --- a/.github/workflows/cicd-ec2.yml +++ b/.github/workflows/cicd-ec2.yml @@ -2,10 +2,10 @@ name: CI/CD using github actions & docker # event trigger -# main이나 develop 브랜치에 push가 되었을 때 실행 +# main이나 staging 브랜치에 push가 되었을 때 실행 on: push: - branches: [ "main", "dev" ] + branches: [ "main", "staging" ] permissions: contents: read @@ -35,7 +35,7 @@ jobs: # 공통 yml 파일 생성 - secret, oauth - name: make application-secret.yml - if: contains(github.ref, 'dev') || contains(github.ref, 'main') + if: contains(github.ref, 'staging') || contains(github.ref, 'main') run: | cd ./genti-api/src/main/resources touch ./application-secret.yml @@ -44,7 +44,7 @@ jobs: # 환경별 yml 파일 생성(3) - deploy - name: make application-deploy.yml - if: contains(github.ref, 'dev') || contains(github.ref, 'main') + if: contains(github.ref, 'staging') || contains(github.ref, 'main') run: | cd ./genti-api/src/main/resources touch ./application-deploy.yml @@ -97,15 +97,15 @@ jobs: source: "./docker/deploy/*" target: "/home/ubuntu/workspace/" - - name: Upload docker compose file to dev server - if: contains(github.ref, 'dev') + - name: Upload docker compose file to staging server + if: contains(github.ref, 'staging') uses: appleboy/scp-action@master with: - host: ${{ secrets.HOST_DEV }} + host: ${{ secrets.HOST_STAGING }} username: ubuntu key: ${{ secrets.EC2_KEY }} port: 22 - source: "./docker/dev/*" + source: "./docker/staging/*" target: "/home/ubuntu/workspace/" # docker build & push to deploy server @@ -116,13 +116,13 @@ jobs: docker build -f Dockerfile_deploy -t ${{ secrets.DOCKER_USERNAME }}/genti-deploy . docker push ${{ secrets.DOCKER_USERNAME }}/genti-deploy - # docker build & push to develop - - name: Docker build & push to dev - if: contains(github.ref, 'dev') + # docker build & push to staging + - name: Docker build & push to staging + if: contains(github.ref, 'staging') run: | docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }} - docker build -f Dockerfile_dev -t ${{ secrets.DOCKER_USERNAME }}/genti-dev . - docker push ${{ secrets.DOCKER_USERNAME }}/genti-dev + docker build -f Dockerfile_staging -t ${{ secrets.DOCKER_USERNAME }}/genti-staging . + docker push ${{ secrets.DOCKER_USERNAME }}/genti-staging ## deploy to deploy server - name: Deploy to deploy server @@ -142,22 +142,22 @@ jobs: sudo docker compose up -d sudo docker image prune -f - ## deploy to dev server - - name: Deploy to dev server + ## deploy to staging server + - name: Deploy to staging server uses: appleboy/ssh-action@master - id: deploy-dev - if: contains(github.ref, 'dev') + id: deploy-staging + if: contains(github.ref, 'staging') with: - host: ${{ secrets.HOST_DEV }} # EC2 퍼블릭 IPv4 DNS + host: ${{ secrets.HOST_STAGING }} # EC2 퍼블릭 IPv4 DNS username: ubuntu password: ${{ secrets.PASSWORD }} port: 22 key: ${{ secrets.EC2_KEY }} script: | sudo docker ps - cd /home/ubuntu/workspace/docker/dev + cd /home/ubuntu/workspace/docker/staging docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }} - sudo docker pull ${{ secrets.DOCKER_USERNAME }}/genti-dev + sudo docker pull ${{ secrets.DOCKER_USERNAME }}/genti-staging sudo docker compose up -d sudo docker image prune -f diff --git a/.gitignore b/.gitignore index 7bbdd949..b5549d4b 100644 --- a/.gitignore +++ b/.gitignore @@ -54,8 +54,12 @@ README_PRIVATE.md ### docker 환경설정 -.env +/docker/.env + +# Include all other .env files +!**/.env logs/ -docker/docker-compose.yml \ No newline at end of file +docker/docker-compose.yml +/docker/.env diff --git a/docker/staging/.env b/docker/staging/.env new file mode 100644 index 00000000..86386acf --- /dev/null +++ b/docker/staging/.env @@ -0,0 +1,13 @@ +# SERVER + +SERVER_BINDING_PORT=8080 +SERVER_CONTAINER_PORT=8080 + +# REDIS +# Docker volume setting +REDIS_DATA_PATH=/home/ubuntu/workspace/redis/volume/redis/data +REDIS_DEFAULT_CONFIG_FILE=/home/workspace/redis/volume/redis/redis.conf + +# etc setting +REDIS_BINDING_PORT=6379 +REDIS_CONTAINER_PORT=6379 \ No newline at end of file diff --git a/docker/dev/docker-compose.yml b/docker/staging/docker-compose.yml similarity index 86% rename from docker/dev/docker-compose.yml rename to docker/staging/docker-compose.yml index 41e3ddc1..959342af 100644 --- a/docker/dev/docker-compose.yml +++ b/docker/staging/docker-compose.yml @@ -2,8 +2,8 @@ version: '3.8' services: genti: - image: byeongryeol/genti-dev:latest - container_name: genti-dev + image: byeongryeol/genti-staging:latest + container_name: genti-staging volumes: - /home/ubuntu/workspace/logs:/logs # 로그 경로 마운트 ports: