-
-
Notifications
You must be signed in to change notification settings - Fork 1
202 lines (175 loc) · 6.73 KB
/
buildPortalDocker.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
# buildProductionDocker.yml
#
# Workflow to build and push a Docker image for running the
# the web-portal at online.interlisp.org. Depending on input, will create
# either an production or a development version of the image. Also,
# input determines amd64 or arm64 - default amd64.
#
# 2022-01-25 by Frank Halasz
#
#
# Copyright: 2022 by Interlisp.org
#
name: 'Build/Push Portal Docker Image'
# Run this workflow on ...
on:
workflow_dispatch:
inputs:
platform:
type: choice
options:
- linux/amd64
- linux/arm64
workflow_call:
secrets:
DOCKER_USERNAME:
required: true
DOCKER_PASSWORD:
required: true
CCRYPT_KEY:
required: true
inputs:
platform:
description: "linux/amd64 or linux/arm64"
type: string
default: 'linux/amd64'
required: false
defaults:
run:
shell: bash
jobs:
# Regularize the inputs so they can be referenced the same way whether they are
# the result of a workflow_dispatch or a workflow_call
inputs:
runs-on: ubuntu-latest
outputs:
platform: ${{ steps.platform.outputs.platform }}
steps:
- id: platform
run: >
if [ '${{ toJSON(inputs) }}' = 'null' ];
then echo "platform=${{ github.event.inputs.platform }}" >> ${GITHUB_OUTPUT};
else echo "platform=${{ inputs.platform }}" >> ${GITHUB_OUTPUT};
fi
# Build and push the docker image
build_and-push:
needs: inputs
runs-on: ubuntu-latest
steps:
# Load ccrypt
- name: Load ccrypt
id: ccrypt
run: sudo apt-get update && sudo apt-get install -y ccrypt
# Checkout the actions for this repo_owner
- name: Checkout Actions
uses: actions/checkout@v4
with:
repository: ${{ github.repository_owner }}/.github
path: ./Actions_${{ github.sha }}
- run: mv ./Actions_${{ github.sha }}/actions ../actions && rm -rf ./Actions_${{ github.sha }}
# Checkout latest commit to depth 1 for production
- name: Checkout Web-portal code
uses: actions/checkout@v4
with:
fetch-depth: 1
# Setup release tag
- name: Setup Release Tag
id: tag
uses: ./../actions/release-tag-action
# Setup docker environment variables
- name: Setup Docker Environment Variables
id: docker_env
run: |
DOCKER_REGISTRY="ghcr.io/"
echo "docker_registry=${DOCKER_REGISTRY}" >> ${GITHUB_OUTPUT}
DOCKER_NAMESPACE=$(echo ${GITHUB_REPOSITORY_OWNER} | tr '[:upper:]' '[:lower:]')
echo "DOCKER_NAMESPACE=${DOCKER_NAMESPACE}" >> ${GITHUB_ENV}
echo "docker_namespace=${DOCKER_NAMESPACE}" >> ${GITHUB_OUTPUT}
#
DOCKER_REPO_PROD=${DOCKER_REGISTRY}${DOCKER_NAMESPACE}/${{ steps.tag.outputs.repo_name }}-production
DOCKER_TAGS_PROD="${DOCKER_REPO_PROD}:latest,${DOCKER_REPO_PROD}:${RELEASE_TAG#*-}"
DOCKER_REPO_DEV=${DOCKER_REGISTRY}${DOCKER_NAMESPACE}/${{ steps.tag.outputs.repo_name }}-development
DOCKER_TAGS_DEV="${DOCKER_REPO_DEV}:latest,${DOCKER_REPO_DEV}:${RELEASE_TAG#*-}"
echo "build_time=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> ${GITHUB_OUTPUT}
echo "docker_tags_prod=${DOCKER_TAGS_PROD}" >> ${GITHUB_OUTPUT}
echo "docker_tags_dev=${DOCKER_TAGS_DEV}" >> ${GITHUB_OUTPUT}
# Setup the Docker Machine Emulation environment.
- name: Set up QEMU
if: ${{ needs.inputs.outputs.platform == 'linux/arm64' }}
uses: docker/setup-qemu-action@v3
with:
platforms: linux/arm64
# Setup the Docker Buildx funtion
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v3
# Online now uses github container registry instead of dockerhub
# Login into DockerHub - required to store the created image
#- name: Login to DockerHub
# uses: docker/login-action@v1
# with:
# username: ${{ steps.docker_env.outputs.docker_namespace }}
# password: ${{ secrets.DOCKER_PASSWORD }}
# Login to ghcr.io
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
# Decrypt secrets in web-portal code
- name: Decrypt cpt files
run: |
cat web-portal/server/js/keys.js.cpt | K="${{ secrets.CCRYPT_KEY }}" ccdecrypt -E "K" > web-portal/server/js/keys.js
# Get novnc
- name: Checkout novnc code
uses: actions/checkout@v4
with:
repository: 'novnc/noVNC.git'
ref: 'v1.3.0'
path: "./web-portal/client/novnc"
# Do the Production Docker Build using the Dockerfile_production
# Push the result to Docker Hub
- name: Build Docker Image for Push to Docker Hub
uses: docker/build-push-action@v5
with:
builder: ${{ steps.buildx.outputs.name }}
build-args: |
BUILD_DATE=${{ steps.docker_env.outputs.build_time }}
DOCKER_NAMESPACE=${{ steps.docker_env.outputs.docker_namespace }}
context: .
file: ./docker_portal/Dockerfile_production
platforms: ${{ needs.inputs.outputs.platform }}
push: true
tags: ${{ steps.docker_env.outputs.docker_tags_prod }}
# Recheckout latest commit with fetch_depth of 0 for development image
- name: Checkout Web-portal code
uses: actions/checkout@v4
with:
fetch-depth: 0
# Decrypt secrets in web-portal code
- name: Decrypt cpt files
run: |
cat web-portal/server/js/keys.js.cpt | K="${{ secrets.CCRYPT_KEY }}" ccdecrypt -E "K" > web-portal/server/js/keys.js
# Get novnc
- name: Checkout novnc code
uses: actions/checkout@v4
with:
repository: 'novnc/noVNC.git'
ref: 'v1.3.0'
path: "./web-portal/client/novnc"
# Do the Development Docker Build using the Dockerfile_development
# Push the result to Docker Hub
- name: Build Docker Image for Push to Docker Hub
uses: docker/build-push-action@v5
with:
builder: ${{ steps.buildx.outputs.name }}
build-args: |
BUILD_DATE=${{ steps.docker_env.outputs.build_time }}
DOCKER_NAMESPACE=${{ steps.docker_env.outputs.docker_namespace }}
DOCKER_REGISTRY=${{ steps.docker_env.outputs.docker_registry }}
context: .
file: ./docker_portal/Dockerfile_development
platforms: ${{ needs.inputs.outputs.platform }}
push: true
tags: ${{ steps.docker_env.outputs.docker_tags_dev }}