-
Notifications
You must be signed in to change notification settings - Fork 0
59 lines (55 loc) · 1.73 KB
/
main.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
name: CI/CD Docker
#on:
# push:
# branches: [ main ]
env:
DOCKER_IMAGE: ghcr.io/${{ github.repository }}
VERSION: ${{ github.sha }}
NAME: ${{ github.repository_id }}
jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up docker buildx
id: buildx
uses: docker/setup-buildx-action@v1
# - name: Cache docker layers
# uses: actions/cache@v2
# with:
# path: /tmp/.buildx-cache
# key: ${{ runner.os }}-buildx-${{ env.VERSION }}
# restore-keys: ${{ runner.os }}-buildx-
- name: Login to ghcr
uses: docker/[email protected]
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GHCR_TOKEN }}
- name: Build and push
id: docker_build
uses: docker/build-push-action@v2
with:
builder: ${{ steps.buildx.outputs.name }}
push: true
tags: ${{ env.DOCKER_IMAGE }}:latest
build-args: |
NOTION_API_KEY=${{ secrets.NOTION_API_KEY }}
deploy:
needs: build
name: Deploy
runs-on: [ self-hosted, label-go ]
steps:
- name: Login to ghcr
uses: docker/[email protected]
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GHCR_TOKEN }}
- name: Docker run
run: |
docker stop ${{ env.NAME }} && docker rm ${{ env.NAME }} && docker rmi ${{ env.DOCKER_IMAGE }}:latest
docker run -d -p 3000:3000 --name ${{ github.repository_id }} --restart always \
-e NOTION_API_KEY=${{ secrets.NOTION_API_KEY }} \
${{ env.DOCKER_IMAGE }}:latest