Skip to content

Commit

Permalink
Fix: #62 dev에 적용되던 ci/cd 파이프라인 로직 dev -> staging으로 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
BYEONGRYEOL committed Jul 20, 2024
1 parent f77a7ad commit 5318279
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 24 deletions.
40 changes: 20 additions & 20 deletions .github/workflows/cicd-ec2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
8 changes: 6 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,12 @@ README_PRIVATE.md

### docker 환경설정

.env
/docker/.env

# Include all other .env files
!**/.env

logs/

docker/docker-compose.yml
docker/docker-compose.yml
/docker/.env
13 changes: 13 additions & 0 deletions docker/staging/.env
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 5318279

Please sign in to comment.