Skip to content

Commit 16f4781

Browse files
committed
👷 Move push release to Docker from Circle to GitHub
⬆️ Upgrade docker/login-action@v2 👷 Inherit secrets 👷 Use `github` context
1 parent 6ca28fa commit 16f4781

File tree

6 files changed

+93
-69
lines changed

6 files changed

+93
-69
lines changed

.circleci/config.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ parameters:
99
default: false
1010
workflows:
1111
setup:
12-
when: always()
12+
when: << pipeline.parameters.run_tests >>
1313
jobs:
1414
- continuation/continue:
1515
configuration_path: ".circleci/main.yml"
1616
parameters: /home/circleci/test.json
1717
pre-steps:
1818
- run:
1919
command: |
20-
echo '{ "owner": "'${CIRCLE_PROJECT_USERNAME}'", "branch": "'${CIRCLE_BRANCH}'", "tag": "'${CIRCLE_TAG}'" }' >> /home/circleci/test.json
20+
echo '{ "owner": "'${CIRCLE_PROJECT_USERNAME}'", "branch": "'${CIRCLE_BRANCH}'" }' >> /home/circleci/test.json
2121
cat /home/circleci/test.json

.circleci/main.yml

Lines changed: 8 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,13 @@ version: 2.1
44
parameters:
55
branch:
66
type: string
7-
default: no branch
7+
default: unknown
88
owner:
99
type: string
1010
default: unknown
1111
run_tests:
1212
type: boolean
1313
default: false
14-
tag:
15-
type: string
16-
default: untagged
1714

1815
commands:
1916
push-to-docker-hub:
@@ -137,19 +134,15 @@ commands:
137134
- run:
138135
name: "Setting up variant"
139136
command: |
140-
if [[ ${CIRCLE_TAG} == '' ]]
137+
if [[ ${CIRCLE_BRANCH} == 'main' ]]
138+
then
139+
TAG=latest
140+
elif [[ ${CIRCLE_BRANCH} == 'develop' ]]
141141
then
142-
if [[ ${CIRCLE_BRANCH} == 'main' ]]
143-
then
144-
TAG=latest
145-
elif [[ ${CIRCLE_BRANCH} == 'develop' ]]
146-
then
147-
TAG=nightly
148-
else
149-
TAG="${CIRCLE_BRANCH//\//_}"
150-
fi
142+
TAG=nightly
151143
else
152-
TAG=${CIRCLE_TAG}
144+
TAG="${CIRCLE_BRANCH//\//_}"
145+
fi
153146
DOCKER_TAG="ghcr.io/${CIRCLE_PROJECT_USERNAME,,}/${CIRCLE_PROJECT_REPONAME,,}:${TAG,,}"
154147
if [[ -n "<< parameters.variant >>" ]]
155148
then
@@ -188,24 +181,6 @@ jobs:
188181
- combine-coverage
189182
- store_artifacts:
190183
path: htmlcov
191-
push-release:
192-
parameters:
193-
variant:
194-
type: string
195-
default: ""
196-
machine:
197-
image: ubuntu-2004:202010-01
198-
resource_class: medium
199-
steps:
200-
- checkout
201-
- set-up-variant:
202-
variant: "<< parameters.variant >>"
203-
- attach_workspace:
204-
at: /home/circleci/
205-
- push-to-docker-hub:
206-
tag: release-$CIRCLE_TAG
207-
- push-to-docker-hub:
208-
tag: latest
209184
push-branch-to-docker-hub:
210185
parameters:
211186
variant:
@@ -284,12 +259,6 @@ workflows:
284259
test:
285260
jobs:
286261
- combine-coverage:
287-
filters: &tagged
288-
branches:
289-
ignore:
290-
- main
291-
tags:
292-
only: /^v.*/
293262
name: "Combine coverage"
294263
requires:
295264
- "Test in Docker"
@@ -304,8 +273,6 @@ workflows:
304273
branches:
305274
only:
306275
- develop
307-
tags:
308-
ignore: /.*/
309276
matrix:
310277
parameters:
311278
variant:
@@ -315,37 +282,21 @@ workflows:
315282
- fMRIPrep-LTS
316283
requires:
317284
- "Combine coverage"
318-
- push-release:
319-
<<: *tagged
320-
matrix:
321-
parameters:
322-
variant:
323-
- ""
324-
- lite
325-
- ABCD-HCP
326-
- fMRIPrep-LTS
327285
- pytest-docker:
328-
<<: *tagged
329286
name: "Test in Docker"
330287
- pytest-docker:
331-
<<: *tagged
332288
name: "Test ABCD-HCP variant in Docker"
333289
variant: ABCD-HCP
334290
- pytest-docker:
335-
<<: *tagged
336291
name: "Test fMRIPrep-LTS variant in Docker"
337292
variant: fMRIPrep-LTS
338293
- pytest-docker:
339-
<<: *tagged
340294
name: "Test lite variant in Docker"
341295
- pytest-singularity:
342-
<<: *tagged
343296
name: "Test in Singularity"
344297
- pytest-singularity:
345-
<<: *tagged
346298
name: "Test ABCD-HCP variant in Singularity"
347299
variant: ABCD-HCP
348300
- pytest-singularity:
349-
<<: *tagged
350301
name: "Test lite variant in Singularity"
351302
variant: lite

.github/workflows/build_C-PAC.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
- name: Set up Docker Buildx
2727
uses: docker/[email protected]
2828
- name: Log in to GitHub Container Registry
29-
uses: docker/login-action@v1
29+
uses: docker/login-action@v2
3030
with:
3131
registry: ghcr.io
3232
username: ${{ github.actor }}

.github/workflows/build_and_test.yml

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ jobs:
4848
- C-PAC-ABCD-HCP
4949
- C-PAC-fMRIPrep-LTS
5050
runs-on: ubuntu-latest
51+
if: github.ref_name == 'develop' || github.ref_name == 'main'
5152
steps:
5253
- name: Check out C-PAC
5354
uses: actions/checkout@v2
@@ -92,6 +93,7 @@ jobs:
9293
- C-PAC-lite
9394
- C-PAC-ABCD-HCP
9495
- C-PAC-fMRIPrep-LTS
96+
if: github.ref_type == 'branch'
9597
runs-on: ubuntu-latest
9698
steps:
9799
- name: Check out C-PAC
@@ -103,12 +105,7 @@ jobs:
103105
echo "ref: $GITHUB_REF_NAME"
104106
TEXT="Triggered pipeline at "
105107
U1="https://circleci.com/api/v2/project/gh/${GITHUB_REPOSITORY}/pipeline"
106-
if [[ "${GITHUB_REF_TYPE}" == "tag" ]]
107-
then
108-
export DATA="{\"tag\":\"$GITHUB_REF_NAME\", \"parameters\": {\"run_tests\": true}}"
109-
else
110-
export DATA="{\"branch\":\"$GITHUB_REF_NAME\", \"parameters\": {\"run_tests\": true}}"
111-
fi
108+
export DATA="{\"branch\":\"$GITHUB_REF_NAME\", \"parameters\": {\"run_tests\": true}}"
112109
echo "URL ${U1}"
113110
echo "data ${DATA}"
114111
PIPELINE_NUMBER=$(curl \
@@ -133,3 +130,39 @@ jobs:
133130
jq '.items[0].id' |
134131
tr -d '"')
135132
echo ${TEXT}https://app.circleci.com/pipelines/github/${GITHUB_REPOSITORY}/${PIPELINE_NUMBER}/workflows/${WORKFLOW_ID}
133+
134+
Deploy_to_Docker_Hub:
135+
needs:
136+
- C-PAC
137+
if: github.ref_type == 'tag'
138+
uses: ./.github/workflows/deploy_to_Docker_Hub.yml
139+
with:
140+
variant: ''
141+
secrets: inherit
142+
143+
Deploy_to_Docker_Hub-lite:
144+
needs:
145+
- C-PAC-lite
146+
if: github.ref_type == 'tag'
147+
uses: ./.github/workflows/deploy_to_Docker_Hub.yml
148+
with:
149+
variant: 'lite'
150+
secrets: inherit
151+
152+
Deploy_to_Docker_Hub-ABCD-HCP:
153+
needs:
154+
- C-PAC-ABCD-HCP
155+
if: github.ref_type == 'tag'
156+
uses: ./.github/workflows/deploy_to_Docker_Hub.yml
157+
with:
158+
variant: 'ABCD-HCP'
159+
secrets: inherit
160+
161+
Deploy_to_Docker_Hub-fMRIPrep-LTS:
162+
needs:
163+
- C-PAC-fMRIPrep-LTS
164+
if: github.ref_type == 'tag'
165+
uses: ./.github/workflows/deploy_to_Docker_Hub.yml
166+
with:
167+
variant: 'fMRIPrep-LTS'
168+
secrets: inherit

.github/workflows/build_stages.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ jobs:
7171
uses: docker/[email protected]
7272
if: contains(steps.changed-files-base.outputs.all_changed_files, matrix.Dockerfile) || contains(steps.changed-files.outputs.all_changed_files, matrix.Dockerfile)
7373
- name: Log in to GitHub Container Registry
74-
uses: docker/login-action@v1
74+
uses: docker/login-action@v2
7575
with:
7676
registry: ghcr.io
7777
username: ${{ github.actor }}
@@ -143,7 +143,7 @@ jobs:
143143
uses: docker/[email protected]
144144
if: contains(steps.changed-files-base.outputs.all_changed_files, matrix.Dockerfile) || contains(steps.changed-files.outputs.all_changed_files, matrix.Dockerfile)
145145
- name: Log in to GitHub Container Registry
146-
uses: docker/login-action@v1
146+
uses: docker/login-action@v2
147147
with:
148148
registry: ghcr.io
149149
username: ${{ github.actor }}
@@ -243,7 +243,7 @@ jobs:
243243
uses: docker/[email protected]
244244
if: always() && steps.changed-files-base.outputs.any_changed == 'true' || steps.changed-files.outputs.any_changed == 'true' || steps.docker_tag.not_yet_exists == 1
245245
- name: Log in to GitHub Container Registry
246-
uses: docker/login-action@v1
246+
uses: docker/login-action@v2
247247
with:
248248
registry: ghcr.io
249249
username: ${{ github.actor }}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Deploy to Docker Hub
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
variant:
7+
required: true
8+
type: string
9+
secrets:
10+
DOCKERHUB_USER:
11+
required: true
12+
DOCKERHUB_TOKEN:
13+
required: true
14+
15+
jobs:
16+
Deploy_to_Docker_Hub:
17+
name: Deploy to Docker Hub
18+
runs-on: ubuntu-latest
19+
steps:
20+
- name: Log in to Docker Hub
21+
uses: docker/login-action@v2
22+
with:
23+
username: ${{ secrets.DOCKERHUB_USER }}
24+
password: ${{ secrets.DOCKERHUB_TOKEN }}
25+
- name: Pull, tag and push
26+
run: |
27+
if [[ "${{ inputs.variant }}" != "" ]]
28+
then
29+
VARIANT=-${{ inputs.variant }}
30+
fi
31+
TAG1=latest$VARIANT
32+
TAG2=release-${{ github.ref_name }}$VARIANT
33+
DOCKER_TAG=$(echo "ghcr.io/${{ github.repository }}" | tr '[:upper:]' '[:lower:]')
34+
echo "original tag: ${DOCKER_TAG}:${TAG1}"
35+
echo "new tags: fcpindi/c-pac:${TAG1} fcpindi/c-pac:${TAG2}"
36+
docker pull ${DOCKER_TAG}:${TAG1}
37+
docker tag ${DOCKER_TAG}:${TAG1} fcpindi/c-pac:${TAG1}
38+
docker tag ${DOCKER_TAG}:${TAG1} fcpindi/c-pac:${TAG2}
39+
docker push fcpindi/c-pac:${TAG1}
40+
docker push fcpindi/c-pac:${TAG2}

0 commit comments

Comments
 (0)