generated from Sage-Bionetworks/docker-rstudio
-
Notifications
You must be signed in to change notification settings - Fork 0
225 lines (204 loc) · 7.62 KB
/
ci.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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
name: CI
on:
schedule:
- cron: '0 10 * * 0' # every Sunday at 10am
push:
branches:
- main
- develop
tags:
- '*.*.*'
pull_request:
env:
docker_repository: sagebionetworks/challenge-analysis
# github.event.repository.clone_url not available for on: schedule
clone_url: https://github.com/Sage-Bionetworks-Challenges/challenge-analysis.git
# github.event.repository.default_branch not available for on: schedule
default_branch: main
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Lint Dockerfiles
uses: docker://hadolint/hadolint:latest
with:
entrypoint: hadolint
args: Dockerfile
- name: Check that packages in requirements.txt files are in asc order
run: |
sort -f --check conda/challenge-analysis/requirements.txt
test:
needs: [lint]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set environment variables
run: |
cp .env.example .env
export $(grep -v '^#' .env | xargs -d '\n')
- name: Validate docker-compose.yml
run: docker-compose -f docker-compose.yml config >/dev/null
build-and-publish:
needs: [test]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Prepare build
id: prep
run: |
DOCKER_IMAGE=${{ env.docker_repository }}
VERSION=noop
PUSH_IMAGE=false
PUSH_NOTEBOOKS=false
if [ "${{ github.event_name }}" = "schedule" ]; then
VERSION=weekly
PUSH_IMAGE=true
PUSH_NOTEBOOKS=true
elif [[ $GITHUB_REF == refs/tags/* ]]; then
VERSION=${GITHUB_REF#refs/tags/}
elif [[ $GITHUB_REF == refs/heads/* ]]; then
VERSION=$(echo ${GITHUB_REF#refs/heads/} | sed -r 's#/+#-#g')
if [ "${{ github.event.repository.default_branch }}" = "$VERSION" ]; then
VERSION=edge
PUSH_IMAGE=true
PUSH_NOTEBOOKS=true
fi
elif [[ $GITHUB_REF == refs/pull/* ]]; then
VERSION=pr-${{ github.event.number }}
PUSH_IMAGE=false
PUSH_NOTEBOOKS=true
fi
TAGS="${DOCKER_IMAGE}:${VERSION}"
if [[ $VERSION =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
MINOR=${VERSION%.*}
MAJOR=${MINOR%.*}
TAGS="$TAGS,${DOCKER_IMAGE}:${MINOR}"
TAGS="$TAGS,${DOCKER_IMAGE}:${MAJOR}"
TAGS="$TAGS,${DOCKER_IMAGE}:latest"
TAGS="$TAGS,${DOCKER_IMAGE}:${VERSION}-${GITHUB_SHA::8}"
PUSH_IMAGE=true
PUSH_NOTEBOOKS=true
# elif [ "${{ github.event_name }}" = "push" ]; then
# TAGS="$TAGS,${DOCKER_IMAGE}:sha-${GITHUB_SHA::8}"
fi
echo ::set-output name=version::${VERSION}
echo ::set-output name=version_major::${MAJOR}
echo ::set-output name=version_minor::${MINOR}
echo ::set-output name=tags::${TAGS}
echo ::set-output name=created::$(date -u +'%Y-%m-%dT%H:%M:%SZ')
echo ::set-output name=push_image::${PUSH_IMAGE}
echo ::set-output name=push_notebooks::${PUSH_NOTEBOOKS}
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- 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 }}-single-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-single-buildx
- name: Login to Docker Hub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build image
uses: docker/build-push-action@v2
with:
context: .
file: Dockerfile
builder: ${{ steps.buildx.outputs.name }}
load: true
push: false
platforms: linux/amd64
tags: rstudio-cached:latest
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new
- name: Create .env
run: |
cp .env.example .env
printf "%s\n" \
"PASSWORD=${{ secrets.RSTUDIO_PASSWORD }}" \
"USERID=$(id -u)" \
"GROUPID=$(id -g)" \
"SYNAPSE_TOKEN=${{ secrets.SYNAPSE_TOKEN }}" | tee -a .env >/dev/null
- name: Generate HTML notebooks
run: |
docker run --rm \
--env-file .env \
-v $(pwd)/notebooks:/data \
rstudio-cached:latest \
render /data/*.Rmd
- name: Push image
if: steps.prep.outputs.push_image == 'true'
id: docker_push
uses: docker/build-push-action@v2
with:
context: .
file: Dockerfile
builder: ${{ steps.buildx.outputs.name }}
push: true
platforms: linux/amd64,linux/arm64
tags: ${{ steps.prep.outputs.tags }}
labels: |
org.opencontainers.image.created=${{ steps.prep.outputs.created }}
org.opencontainers.image.source=${{ github.repositoryUrl }}
org.opencontainers.image.version=${{ steps.prep.outputs.version }}
org.opencontainers.image.revision=${{ github.sha }}
org.opencontainers.image.licenses=${{ github.event.repository.license.name }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new
- name: Update Docker Hub repository description
if: steps.prep.outputs.push_image == 'true'
uses: peter-evans/dockerhub-description@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
repository: ${{ env.docker_repository }}
- name: Prepare to publish HTML notebooks to GH Pages
if: steps.prep.outputs.push_notebooks == 'true'
run: |
git clone ${{ env.clone_url }} \
--branch gh-pages --single-branch gh-pages
# Update gh-pages: version specified
NOTEBOOKS_TARGET_DIR=gh-pages/${{ steps.prep.outputs.version }}/notebooks
rm -fr ${NOTEBOOKS_TARGET_DIR}
mkdir -p ${NOTEBOOKS_TARGET_DIR}
cp -R notebooks/*.html ${NOTEBOOKS_TARGET_DIR}
# Update gh-pages: latest, major, and minor versions
if [ ! -z "${{ steps.prep.outputs.version_major }}" ]; then
# Update latest (e.g. "1.2.3" => "latest")
NOTEBOOKS_TARGET_DIR=gh-pages/latest/notebooks
rm -fr ${NOTEBOOKS_TARGET_DIR}
mkdir -p ${NOTEBOOKS_TARGET_DIR}
cp -R notebooks/*.html ${NOTEBOOKS_TARGET_DIR}
# Update major version (e.g. "1.2.3" => "1")
NOTEBOOKS_TARGET_DIR=gh-pages/${{ steps.prep.outputs.version_major }}/notebooks
rm -fr ${NOTEBOOKS_TARGET_DIR}
mkdir -p ${NOTEBOOKS_TARGET_DIR}
cp -R notebooks/*.html ${NOTEBOOKS_TARGET_DIR}
# Update minor version (e.g. "1.2.3" => "1.2")
NOTEBOOKS_TARGET_DIR=gh-pages/${{ steps.prep.outputs.version_minor }}/notebooks
rm -fr ${NOTEBOOKS_TARGET_DIR}
mkdir -p ${NOTEBOOKS_TARGET_DIR}
cp -R notebooks/*.html ${NOTEBOOKS_TARGET_DIR}
fi
cd gh-pages
git config --local user.email "[email protected]"
git config --local user.name "GitHub Action"
git add .
git commit -m "Update notebooks" -a || true
# The above command will fail if no changes were present, so we ignore
# that.
- name: Push to gh-pages
if: steps.prep.outputs.push_notebooks == 'true'
uses: ad-m/github-push-action@master
with:
branch: gh-pages
directory: gh-pages
github_token: ${{ secrets.GITHUB_TOKEN }}
force: true