Skip to content

Commit

Permalink
[LIB-227] CI/CD 파이프라인 (#238)
Browse files Browse the repository at this point in the history
* ci: Build and push Docker image for PROD

Co-authored-by: hseungho <[email protected]>

* ci: Build and push Docker image for Dev

Co-authored-by: hseungho <[email protected]>

* cd: Deploy production Docker image to AWS EC2

Co-authored-by: hseungho <[email protected]>

* cd: Deploy dev Docker image to AWS EC2

Co-authored-by: hseungho <[email protected]>

* test: Update ci/cd Dev workflow trigger for test

Co-authored-by: hseungho <[email protected]>

* fix: Update dev deployment workflow

Co-authored-by: hseungho <[email protected]>

* fix: Update dev deployment workflow

* Revert "fix: Update dev deployment workflow"

This reverts commit 4a3380b.

* fix: Update dev CI workflow

* fix: Update dev CI workflow

* fix: Update dev CI workflow

* fix: Update dev CI workflow

* fix: Update dev CI workflow

* fix: Update dev CI workflow

* fix: Update dev CI workflow

* fix: Update dev CI workflow

* fix: Update dev CI workflow

* fix: Update dev CI workflow

* fix: Update dev CI workflow

* fix: Update dev CI workflow

* fix: Update dev CI workflow

* fix: Update dev CI workflow

* fix: Update dev CI workflow

* fix: Update dev CI workflow

---------

Co-authored-by: hseungho <[email protected]>
  • Loading branch information
ImKunYoung and hseungho authored Sep 26, 2023
1 parent 5dc6b9b commit a697bda
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 5 deletions.
43 changes: 43 additions & 0 deletions .github/workflows/deploy-dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Deploy dev

on:
workflow_run:
workflows:
- Build and Push Docker Image for DEV
types:
- completed

jobs:
deploy:
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' }}

env:
DOCKER_REGISTRY: ghcr.io
DOCKER_REPO: liberty52/liberty52-product-server

steps:
- name: Get latest Release tag
id: latest-tag
uses: robinraju/[email protected]
with:
latest: true
token: ${{ secrets.GITHUB_TOKEN }}

- name: Set Docker Image Name
id: new-docker-image
run: echo "::set-output name=image_name::$DOCKER_REGISTRY/$DOCKER_REPO:dev-${{ steps.latest-tag.outputs.tag_name }}"

- name: Deploy AWS EC2 dev
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.REMOTE_IP_DEV }}
username: ${{ secrets.REMOTE_SSH_ID_DEV }}
key: ${{ secrets.REMOTE_SSH_KEY_DEV }}
port: ${{ secrets.REMOTE_SSH_PORT_DEV }}
script: |
echo ${{ secrets.GTOKEN }} | sudo docker login ghcr.io -u ${{ github.actor }} --password-stdin
sudo docker pull ${{ steps.new-docker-image.outputs.image_name }}
container_name=$(sudo docker ps | grep liberty52 | awk '{print $NF}')
sudo docker stop $container_name
sudo docker run -d -p 8080:8080 ${{ steps.new-docker-image.outputs.image_name }}
30 changes: 30 additions & 0 deletions .github/workflows/deploy-prod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Deploy prod

on:
workflow_run:
workflows:
- "Build and Push Docker Image for PROD"
types:
- completed

jobs:
deploy:
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' }}
env:
DOCKER_IMAGE: ghcr.io/liberty52/liberty52-product-server:prod-${{ github.sha }}

steps:
- name: Deploy AWS EC2 dev
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.REMOTE_IP_PROD }}
username: ${{ secrets.REMOTE_SSH_ID_PROD }}
key: ${{ secrets.REMOTE_SSH_KEY_PROD }}
port: ${{ secrets.REMOTE_SSH_PORT_PROD }}
script: |
echo ${{ secrets.GTOKEN }} | sudo docker login ghcr.io -u ${{ github.actor }} --password-stdin
sudo docker pull $DOCKER_IMAGE
container_name=$(sudo docker ps | grep liberty52 | awk '{print $NF}')
sudo docker stop $container_name
sudo docker run -d -p 8080:8080 $DOCKER_IMAGE
6 changes: 3 additions & 3 deletions .github/workflows/docker-ci-dev.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Build and Push Docker Dev Image
name: Build and Push Docker Image for DEV

on:
push:
Expand Down Expand Up @@ -27,7 +27,7 @@ jobs:
run: |
echo "::set-output name=release_name::v-$(date +'%Y.%m.%d-%H%M%S')"
- name: Build And Push Docker Dev Image
- name: Build and Push Docker Dev Image
run: |
RELEASE_NAME="${{ steps.release_name.outputs.release_name }}"
docker build --build-arg SPRING_PROFILES_ACTIVE=dev -t my-product-server:latest -f multistage.Dockerfile .
Expand All @@ -46,4 +46,4 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GTOKEN }}

- name: Clean up
run: docker logout ghcr.io
run: docker logout ghcr.io
4 changes: 2 additions & 2 deletions .github/workflows/docker-ci-prod.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Build and Push Docker Prod Image
name: Build and Push Docker Image for PROD

on:
push:
Expand Down Expand Up @@ -29,4 +29,4 @@ jobs:
docker push ghcr.io/liberty52/liberty52-product-server:prod-v${{ github.sha }}
- name: Clean up
run: docker logout ghcr.io
run: docker logout ghcr.io

0 comments on commit a697bda

Please sign in to comment.