-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #124 from sparcs-kaist/feat/dev-prod-continuous-de…
…ployment
- Loading branch information
Showing
4 changed files
with
140 additions
and
0 deletions.
There are no files selected for viewing
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
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 |
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
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 |
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
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 |
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
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 |