-
Notifications
You must be signed in to change notification settings - Fork 7
164 lines (146 loc) · 6.08 KB
/
apps-docker.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
name: Docker
on:
push:
branches:
- docker**
# https://help.github.com/en/actions/automating-your-workflow-with-github-actions/workflow-syntax-for-github-actions#onschedule
schedule:
- cron: "0 3 * * 1-5" # every work night (delayed 1 hr)
repository_dispatch:
types:
- all
# Trigger with `shinycoreci::trigger_docker()`
- docker
jobs:
config:
uses: ./.github/workflows/apps-config.yml
docker:
needs: config
name: ${{ matrix.docker.type }}-${{ matrix.r_version }}${{ matrix.flavor.extra_base_tag }}
runs-on: ubuntu-latest
strategy:
max-parallel: 5
fail-fast: false
matrix:
flavor:
# - shinycoreci_sha: main
- shinycoreci_sha: main
extra_base_tag: ""
# - shinycoreci_sha: shiny-1.4.0.1
# extra_base_tag: "-rc_v1.4.0.1"
r_version:
- ${{ needs.config.outputs.release }}
- ${{ needs.config.outputs.oldrel1 }}
- ${{ needs.config.outputs.oldrel2 }}
- ${{ needs.config.outputs.oldrel3 }}
- ${{ needs.config.outputs.oldrel4 }}
docker:
# - workdir: inst/Docker/centos
# type: centos7
- workdir: inst/Docker/ubuntu
type: jammy
- workdir: inst/Docker/ubuntu
type: focal
steps:
- name: Short R version and SHA
id: short
run: |
# keep only the major.minor values
RVERSION=`echo '${{ matrix.r_version }}' | sed 's/\([0-9]\.[0-9]\).*/\1/'`
echo "r-version: $RVERSION"
echo "r-version=$RVERSION" >> $GITHUB_OUTPUT
SHA="${{github.event.pull_request.head.sha}}${{ github.sha }}"
if [[ -z "$SHA" ]]; then
SHA=${{ github.sha }}
fi
SHORT_SHA=${SHA:0:7}
echo "sha: $SHORT_SHA"
echo "sha=$SHORT_SHA" >> $GITHUB_OUTPUT
- uses: actions/checkout@v4
if: steps.can-build.conclusion != 'skipped'
- name: Log in to the Container registry
if: steps.can-build.conclusion != 'skipped'
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build Base
if: steps.can-build.conclusion != 'skipped'
uses: docker/build-push-action@v3
with:
context: ${{ matrix.docker.workdir }}
push: true
tags: |
ghcr.io/${{ github.repository }}:base-${{ steps.short.outputs.r-version }}-${{ matrix.docker.type }}${{ matrix.flavor.extra_base_tag }}
build-args: |
R_VERSION=${{ steps.short.outputs.r-version }}
RELEASE=${{ matrix.docker.type }}
SHINYCORECI_SHA=${{ matrix.flavor.shinycoreci_sha }}
GITHUB_PAT=${{ secrets.GITHUB_TOKEN }}
- name: Build SSO
if: steps.can-build.conclusion != 'skipped'
uses: docker/build-push-action@v2
with:
context: "${{ matrix.docker.workdir }}_sso"
push: true
tags: |
ghcr.io/${{ github.repository }}:sso-${{ steps.short.outputs.r-version }}-${{ matrix.docker.type }}${{ matrix.flavor.extra_base_tag }}
build-args: |
R_VERSION=${{ steps.short.outputs.r-version }}
RELEASE=${{ matrix.docker.type }}
EXTRA_BASE_TAG=${{ matrix.flavor.extra_base_tag }}
- name: Build SSP
if: steps.can-build.conclusion != 'skipped'
uses: docker/build-push-action@v2
with:
context: "${{ matrix.docker.workdir }}_ssp"
push: true
tags: |
ghcr.io/${{ github.repository }}:ssp-${{ steps.short.outputs.r-version }}-${{ matrix.docker.type }}${{ matrix.flavor.extra_base_tag }}
build-args: |
R_VERSION=${{ steps.short.outputs.r-version }}
RELEASE=${{ matrix.docker.type }}
EXTRA_BASE_TAG=${{ matrix.flavor.extra_base_tag }}
docker-cleanup:
if: success() || failure()
needs: [docker]
runs-on: ubuntu-latest
name: Cleanup images
steps:
# Inspiration: https://github.com/jcansdale-test/ghcr-delete-untagged-images/blob/36e56b47bfb6ee9208b4061959f6d0c615e3c5cc/.github/workflows/delete.yml
- name: Delete untagged images
uses: actions/github-script@v6
with:
github-token: ${{ secrets.DOCKER_DELETE_IMAGES }}
script: |
// const response_list = await github.request("GET /orgs/rstudio/packages?package_type=container&visibility=public");
// console.log(JSON.stringify(response_list, null, " "))
let found = true
// Don't try forever if something goes wrong
let retryCount = 0
let n = 100
n = Math.min(100, n) // API has max of 100
while (found && retryCount < 10) {
found = false
retryCount += 1
// GET /orgs/{org}/packages/{package_type}/{package_name}/versions
const response = await github.request("GET /orgs/rstudio/packages/container/shinycoreci/versions",
{ per_page: n }
);
// console.log(JSON.stringify(response, null, " "))
console.log("\n\nRequest count: ", retryCount, "\nVersion count: ", response.data.length, "\n")
for(version of response.data) {
if (version.metadata.container.tags.length == 0) {
console.log("delete " + version.id)
// DELETE /orgs/{org}/packages/{package_type}/{package_name}/versions/{package_version_id}
const deleteResponse = await github.request("DELETE /orgs/rstudio/packages/container/shinycoreci/versions/" + version.id, { });
console.log("status " + deleteResponse.status)
if (deleteResponse.status == 204) {
// We have less than `n` tags
// If `n` versions are returned, then try again
found = response.data.length == n
}
}
}
}