Category Casecade 관련 수정 후 배포 (09.15) #6
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
name: deploy | |
on: | |
push: | |
branches: [deploy] | |
pull_request: | |
branches: [deploy] | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
outputs: | |
version: ${{ steps.meta.outputs.version }} | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Create .env file | |
run: | | |
jq -r 'to_entries|map("\(.key)=\(.value|tostring)")|.[]' <<< "$SECRETS_CONTEXT" > .env | |
env: | |
SECRETS_CONTEXT: ${{ toJson(secrets) }} | |
- name: Docker Hub Login | |
uses: docker/login-action@v2 | |
with: | |
username: ${{ secrets.DOCKER_HUB_USERNAME }} | |
password: ${{secrets.DOCKER_HUB_TOKEN}} | |
- name: Extract metadata (tags, labels) for Docker | |
id: meta | |
uses: docker/metadata-action@v4 | |
with: | |
images: ${{ secrets.DOCKER_HUB_NAMESPACE }}/${{ secrets.DOCKER_HUB_REPO }} | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
- name: Build and push | |
uses: docker/build-push-action@v4 | |
with: | |
context: . | |
push: true | |
platforms: ${{ vars.DOCKER_SERVER_PLATFORM }} | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} | |
deploy: | |
needs: build | |
runs-on: self-hosted | |
steps: | |
- name: Stop docker container | |
continue-on-error: true | |
run: | | |
docker stop plandar-server-container | |
docker rm plandar-server-container | |
- name: Delete docker images | |
continue-on-error: true | |
env: | |
NAME: ${{ secrets.DOCKER_HUB_NAMESPACE }} | |
REPO: ${{ secrets.DOCKER_HUB_REPO }} | |
run: docker images | grep $NAME/$REPO | tr -s ' ' | cut -d ' ' -f 2 | xargs -I {} docker rmi $NAME/$REPO:{} | |
- name: Pull docker image | |
env: | |
NAME: ${{ secrets.DOCKER_HUB_NAMESPACE }} | |
REPO: ${{ secrets.DOCKER_HUB_REPO }} | |
VERS: ${{ needs.build.outputs.version }} | |
run: docker pull $NAME/$REPO:$VERS | |
- name: Run docker container | |
env: | |
NAME: ${{ secrets.DOCKER_HUB_NAMESPACE }} | |
REPO: ${{ secrets.DOCKER_HUB_REPO }} | |
VERS: ${{ needs.build.outputs.version }} | |
run: docker run --name plandar-server-container -p 4000:4000 -d --link plandar-db-container $NAME/$REPO:$VERS |