Skip to content

Commit

Permalink
Merge pull request #124 from sparcs-kaist/feat/dev-prod-continuous-de…
Browse files Browse the repository at this point in the history
…ployment
  • Loading branch information
withSang authored Sep 17, 2023
2 parents a5e89b9 + e14056b commit bf46be5
Show file tree
Hide file tree
Showing 4 changed files with 140 additions and 0 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/dev-build-image.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Build docker image on push to develop

on:
push:
branches: ["develop"]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Cache Docker layers
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Log in to GitHub Container Registry
run: echo ${{ secrets.GITHUB_TOKEN }} | docker login ghcr.io -u USERNAME --password-stdin
- name: Build and push Image
id: docker-build
uses: docker/build-push-action@v5
env:
IMAGE_TAG: dev
with:
push: true
tags: "ghcr.io/sparcs-kaist/zabo-server:${{ env.IMAGE_TAG }}"
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new
- name: Remove old cache
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
32 changes: 32 additions & 0 deletions .github/workflows/dev-deploy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Deploy to dev server

# when dev image build action is completed, run this action
on:
workflow_run:
workflows: ["Build docker image on push to develop"]
types:
- completed

jobs:
if_workflow_success:
name: Deploy to dev server
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' }}

steps:
- name: pull the image and restart the container
uses: appleboy/ssh-action@v1.0.0
with:
host: ${{ secrets.DEV_HOST }}
port: ${{ secrets.DEV_PORT }}
username: ${{ secrets.DEV_USERNAME }}
password: ${{ secrets.DEV_PASSWORD }}
proxy_host: ${{ secrets.DEV_PROXY_HOST }}
proxy_port: ${{ secrets.DEV_PROXY_PORT }}
proxy_username: ${{ secrets.DEV_PROXY_USERNAME }}
proxy_password: ${{ secrets.DEV_PROXY_PASSWORD }}
script_stop: true # stop script if any command has failed
script: |
cd ${{ secrets.DEV_WORKING_DIRECTORY }}
docker compose -f .docker/docker-compose.stage.yml -p zabo --env-file=.docker/.env.prod pull
docker compose -f .docker/docker-compose.stage.yml -p zabo --env-file=.docker/.env.prod up --force-recreate --build -d
40 changes: 40 additions & 0 deletions .github/workflows/prod-build-image.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Build docker image on release tag created

on:
push:
tags:
- "**"

jobs:
build:
name: Build and push Image to GitHub Container Registry
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Cache Docker layers
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Log in to GitHub Container Registry
run: echo ${{ secrets.GITHUB_TOKEN }} | docker login ghcr.io -u USERNAME --password-stdin
- name: Build and push Image
id: docker-build
uses: docker/build-push-action@v5
env:
IMAGE_TAG: ${{github.ref_name}}
with:
push: true
tags: |
"ghcr.io/sparcs-kaist/zabo-server:${{ env.IMAGE_TAG }}"
"ghcr.io/sparcs-kaist/zabo-server:latest"
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new
- name: Remove old cache
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
32 changes: 32 additions & 0 deletions .github/workflows/prod-deploy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Deploy to prod server

# when prod image build action is completed, run this action
on:
workflow_run:
workflows: ["Build docker image on release tag created"]
types:
- completed

jobs:
if_workflow_success:
name: Deploy to prod server
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' }}

steps:
- name: pull the image and restart the container
uses: appleboy/ssh-action@v1.0.0
with:
host: ${{ secrets.PROD_HOST }}
port: ${{ secrets.PROD_PORT }}
username: ${{ secrets.PROD_USERNAME }}
password: ${{ secrets.PROD_PASSWORD }}
proxy_host: ${{ secrets.PROD_PROXY_HOST }}
proxy_port: ${{ secrets.PROD_PROXY_PORT }}
proxy_username: ${{ secrets.PROD_PROXY_USERNAME }}
proxy_password: ${{ secrets.PROD_PROXY_PASSWORD }}
script_stop: true # stop script if any command has failed
script: |
cd ${{ secrets.PROD_WORKING_DIRECTORY }}
yarn docker:prod pull
yarn docker:prod up --force-recreate --build -d

0 comments on commit bf46be5

Please sign in to comment.