Skip to content

Commit

Permalink
Merge pull request #173 from sparcs-kaist/feat/production-deploy-on-r…
Browse files Browse the repository at this point in the history
…elease
  • Loading branch information
withSang authored Sep 16, 2023
2 parents 33d5eae + 84312a9 commit 605d8fb
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 6 deletions.
9 changes: 4 additions & 5 deletions .github/workflows/dev-build-image.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,24 @@ jobs:
steps:
- uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
uses: docker/setup-buildx-action@v3
- name: Cache Docker layers
uses: actions/cache@v2
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
- 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@v2
uses: docker/build-push-action@v5
env:
IMAGE_TAG: dev
with:
push: true
tags: "ghcr.io/sparcs-kaist/zabo-front:${{ env.IMAGE_TAG }}"
# (3)
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new
- name: Remove old cache
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/dev-deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ jobs:
script: |
docker pull ghcr.io/sparcs-kaist/zabo-front:dev
docker rm -f zabo-front
docker run --restart always -d -p 15081:80 --name zabo-front ghcr.io/sparcs-kaist/zabo-front:dev
docker run --restart always -d -p ${{ secrets.DEV_CONTAINER_PORT }}:80 --name zabo-front ghcr.io/sparcs-kaist/zabo-front:dev
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:
- v**

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-front:${{ env.IMAGE_TAG }}"
"ghcr.io/sparcs-kaist/zabo-front: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 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.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: |
docker pull ghcr.io/sparcs-kaist/zabo-front:latest
docker rm -f zabo-front
docker run --restart always -d -p ${{ secrets.PROD_CONTAINER_PORT }}:80 --name zabo-front ghcr.io/sparcs-kaist/zabo-front:latest
23 changes: 23 additions & 0 deletions .github/workflows/prod-release-tag.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# This workflow was created by Ted Park
# Source: https://medium.com/prnd/github%EC%97%90%EC%84%9C-release-tag-%EC%9E%90%EB%8F%99%EC%9C%BC%EB%A1%9C-%EB%A7%8C%EB%93%A4%EC%96%B4-%EC%A3%BC%EA%B8%B0-1%EB%B6%84%EB%A7%8C%EC%97%90-%EC%84%A4%EC%A0%95-5c09a383fb08

name: Create Release Tag on push to main
on:
push:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Extract tag version
run: echo "##[set-output name=version;]$(echo '${{ github.event.head_commit.message }}' | egrep -o '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}')"
id: extract_version_name
- name: Create release with tag
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.extract_version_name.outputs.version }}
release_name: ${{ steps.extract_version_name.outputs.version }}

0 comments on commit 605d8fb

Please sign in to comment.