-
Notifications
You must be signed in to change notification settings - Fork 12
160 lines (150 loc) · 5.79 KB
/
build-neurodesktop-dev.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
name: Build neurodesktop-dev
# Scheduled production builds at 17:00 UTC every day.
# Build manually from here: https://github.com/NeuroDesk/neurodesktop/actions/workflows/build-neurodesktop.yml
# DockerHub: https://hub.docker.com/r/vnmd/neurodesktop
# Github Packages: https://github.com/NeuroDesk/neurodesktop/pkgs/container/neurodesktop%2Fneurodesktop
on:
workflow_dispatch:
inputs:
force_push:
description: 'Force push?'
type: boolean
required: true
default: false
# schedule:
# - cron: '0 17 * * *'
env:
DOCKERHUB_ORG: ${{ vars.DOCKERHUB_ORG }}
jobs:
build-image:
runs-on: ubuntu-22.04
steps:
- name: Fetch github api rate limit
run: |
GITHUB_RATE_REMAINING=$(curl -H "Accept: application/vnd.github.v3+json" https://api.github.com/rate_limit | jq '.rate.remaining')
echo "GITHUB_RATE_REMAINING=${GITHUB_RATE_REMAINING}"
echo "GITHUB_RATE_REMAINING=$GITHUB_RATE_REMAINING" >> $GITHUB_ENV
# - name: Maximize build space
# uses: easimon/maximize-build-space@master
# with:
# root-reserve-mb: 40000
# swap-size-mb: 1024
# overprovision-lvm: 'true'
# remove-dotnet: 'true'
# remove-android: 'true'
# remove-haskell: 'true'
# remove-codeql: 'true'
# remove-docker-images: 'true'
- name: Checkout repository
if: ${{ env.GITHUB_RATE_REMAINING > 0 }}
uses: actions/checkout@v4
with:
ref: ${{ github.ref }}
- name: Set environment variables
if: ${{ env.GITHUB_RATE_REMAINING > 0 }}
run: |
IMAGENAME="neurodesktop-dev"
BUILDDATE=`date +%Y-%m-%d-%H%M`
IMAGEID=ghcr.io/$GITHUB_REPOSITORY/$IMAGENAME
IMAGEID=$(echo $IMAGEID | tr '[A-Z]' '[a-z]')
echo "BUILDDATE=$BUILDDATE"
echo "IMAGEID=$IMAGEID"
echo "IMAGENAME=$IMAGENAME"
echo "BUILDDATE=$BUILDDATE" >> $GITHUB_ENV
echo "IMAGEID=$IMAGEID" >> $GITHUB_ENV
echo "IMAGENAME=$IMAGENAME" >> $GITHUB_ENV
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Get rootfs of cached image
run: |
docker pull $IMAGEID:latest && ROOTFS_CACHE=$(docker inspect --format='{{.RootFS}}' $IMAGEID:latest) && docker rmi $IMAGEID:latest || true
echo "ROOTFS_CACHE=$ROOTFS_CACHE" >> $GITHUB_ENV
- name: Build new image
uses: docker/build-push-action@v5
with:
context: .
load: true
tags: ${{ env.IMAGEID }}:${{ env.BUILDDATE }}
cache-from: type=registry,ref=${{ env.IMAGEID }}:latest
cache-to: type=inline
- name: Get rootfs of new image
run: |
ROOTFS_NEW=$(docker inspect --format='{{.RootFS}}' $IMAGEID:$BUILDDATE)
PUSH_IMAGES="${IMAGEID}"
if [ ! -z "${DOCKERHUB_ORG}" ]; then
PUSH_IMAGES="${PUSH_IMAGES}, ${DOCKERHUB_ORG}/${IMAGENAME}"
fi
echo "PUSH_IMAGES=$PUSH_IMAGES"
echo "ROOTFS_NEW=$ROOTFS_NEW" >> $GITHUB_ENV
echo "PUSH_IMAGES=$PUSH_IMAGES" >> $GITHUB_ENV
- name: Login to DockerHub (if changes found)
if: ${{ env.DOCKERHUB_ORG != '' && (env.ROOTFS_NEW != env.ROOTFS_CACHE || github.event.inputs.force_push == 'true') }}
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Get new image metadata (if changes found)
if: ${{ env.ROOTFS_NEW != env.ROOTFS_CACHE || github.event.inputs.force_push == 'true' }}
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.PUSH_IMAGES }}
tags: |
${{ env.BUILDDATE }}
latest
labels: |
org.opencontainers.image.description=Neurodesktop
- name: Push new image (if changes found)
if: ${{ env.ROOTFS_NEW != env.ROOTFS_CACHE || github.event.inputs.force_push == 'true' }}
uses: docker/build-push-action@v5
with:
context: .
# platforms: linux/amd64
platforms: linux/amd64,linux/arm64
provenance: false # fixes unknown/unknown arch builds
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=registry,ref=${{ env.IMAGEID }}:latest
cache-to: type=inline
scan-image:
needs: build-image
runs-on: ubuntu-22.04
steps:
- name: Set environment variables
run: |
IMAGENAME="neurodesktop-dev"
BUILDDATE=`date +%Y-%m-%d-%H%M`
IMAGEID=ghcr.io/$GITHUB_REPOSITORY/$IMAGENAME
IMAGEID=$(echo $IMAGEID | tr '[A-Z]' '[a-z]')
echo "BUILDDATE=$BUILDDATE"
echo "IMAGEID=$IMAGEID"
echo "IMAGENAME=$IMAGENAME"
echo "BUILDDATE=$BUILDDATE" >> $GITHUB_ENV
echo "IMAGEID=$IMAGEID" >> $GITHUB_ENV
echo "IMAGENAME=$IMAGENAME" >> $GITHUB_ENV
- name: Login to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Pull container image
run: docker pull $IMAGEID:latest
- name: Scan container image
uses: aquasecurity/[email protected]
with:
image-ref: ${{ env.IMAGEID }}:latest
format: table
exit-code: '1'
severity: CRITICAL
timeout: 25m0s
skip-files: /opt/rclone-v1.60.1-linux-amd64/README.txt, /opt/rclone-v1.60.1-linux-amd64/README.html, /opt/rclone-v1.60.1-linux-amd64/rclone.1