-
Notifications
You must be signed in to change notification settings - Fork 0
97 lines (94 loc) · 2.92 KB
/
cd.yml
File metadata and controls
97 lines (94 loc) · 2.92 KB
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
---
name: CD
'on':
workflow_run:
workflows:
- CI
types:
- completed
branches:
- main
tags:
- '*'
jobs:
build_push_images:
if: github.event.workflow_run.conclusion == 'success'
runs-on:
- self-hosted
- Linux
- DEV1-L
timeout-minutes: 150
env:
DOCKER_BASE_IMAGE: "logpass/node"
strategy:
max-parallel: 2
matrix:
context:
- build-type: RelWithDebInfo
tag-suffix: ''
- build-type: Debug
tag-suffix: -debug
steps:
- name: clean after previous run
working-directory: /tmp
run: |
sudo rm -rf "${{ github.workspace }}" \
&& mkdir -p "${{ github.workspace }}"
- uses: actions/checkout@v3
- name: set up qemu
uses: docker/setup-qemu-action@v1.2.0
- name: set up docker buildx
uses: docker/setup-buildx-action@v1
- name: login to dockerhub
uses: docker/login-action@v1.14.1
with:
username: "${{ secrets.DOCKERHUB_USERNAME }}"
password: "${{ secrets.DOCKERHUB_TOKEN }}"
# NOTE: self-hosted GitHub Actions runners can be hosted on one
# machine
logout: false
- name: populate dynamic environment variables
run: |
DOCKER_TAG="latest"
if [[ "${GITHUB_REF}" == "refs/tags/"* ]];
then
DOCKER_TAG="${GITHUB_REF#refs/tags/}"
fi
DOCKER_TAG="${DOCKER_TAG}${{ matrix.context.tag-suffix }}"
echo "DOCKER_TAG=${DOCKER_TAG}" >> ${GITHUB_ENV}
- name: build and push production image
uses: docker/build-push-action@v2
env:
DOCKER_CACHE_IMAGE: >-
${{ env.DOCKER_BASE_IMAGE }}:cache${{ matrix.context.tag-suffix }}
with:
context: .
file: ./.devops/docker/Dockerfile
target: production-stage
build-args: |
LOGPASS_ENV=production
BUILD_TYPE=${{ matrix.context.build-type }}
push: true
cache-from: |
type=registry,ref=${{ env.DOCKER_CACHE_IMAGE }}
type=registry,ref=${{ env.DOCKER_BASE_IMAGE }}:${{ env.DOCKER_TAG }}
cache-to: |
type=registry,ref=${{ env.DOCKER_CACHE_IMAGE }},mode=all
tags: |
${{ env.DOCKER_BASE_IMAGE }}:${{ env.DOCKER_TAG }}
${{ env.DOCKER_BASE_IMAGE }}:${{ github.sha }}
- name: sync docker image README.md
uses: peter-evans/dockerhub-description@v3
with:
username: "${{ secrets.DOCKERHUB_USERNAME }}"
password: "${{ secrets.DOCKERHUB_PASSWORD }}"
repository: "${{ env.DOCKER_BASE_IMAGE }}"
readme-filepath: ".devops/docker/README.md"
- name: clean docker system
if: always()
run: |
docker system prune \
--all \
--filter "until=2h" \
--force \
|| true