generated from JiPyoTak/nest-js-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 1
78 lines (65 loc) · 2.25 KB
/
deploy.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
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