Skip to content

Commit

Permalink
👷 Move push release to Docker from Circle to GitHub
Browse files Browse the repository at this point in the history
⬆️ Upgrade docker/login-action@v2

👷 Inherit secrets

👷 Use `github` context
  • Loading branch information
shnizzedy committed Jun 30, 2022
1 parent 6ca28fa commit 16f4781
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 69 deletions.
4 changes: 2 additions & 2 deletions .circleci/config.yml
Expand Up @@ -9,13 +9,13 @@ parameters:
default: false
workflows:
setup:
when: always()
when: << pipeline.parameters.run_tests >>
jobs:
- continuation/continue:
configuration_path: ".circleci/main.yml"
parameters: /home/circleci/test.json
pre-steps:
- run:
command: |
echo '{ "owner": "'${CIRCLE_PROJECT_USERNAME}'", "branch": "'${CIRCLE_BRANCH}'", "tag": "'${CIRCLE_TAG}'" }' >> /home/circleci/test.json
echo '{ "owner": "'${CIRCLE_PROJECT_USERNAME}'", "branch": "'${CIRCLE_BRANCH}'" }' >> /home/circleci/test.json
cat /home/circleci/test.json
65 changes: 8 additions & 57 deletions .circleci/main.yml
Expand Up @@ -4,16 +4,13 @@ version: 2.1
parameters:
branch:
type: string
default: no branch
default: unknown
owner:
type: string
default: unknown
run_tests:
type: boolean
default: false
tag:
type: string
default: untagged

commands:
push-to-docker-hub:
Expand Down Expand Up @@ -137,19 +134,15 @@ commands:
- run:
name: "Setting up variant"
command: |
if [[ ${CIRCLE_TAG} == '' ]]
if [[ ${CIRCLE_BRANCH} == 'main' ]]
then
TAG=latest
elif [[ ${CIRCLE_BRANCH} == 'develop' ]]
then
if [[ ${CIRCLE_BRANCH} == 'main' ]]
then
TAG=latest
elif [[ ${CIRCLE_BRANCH} == 'develop' ]]
then
TAG=nightly
else
TAG="${CIRCLE_BRANCH//\//_}"
fi
TAG=nightly
else
TAG=${CIRCLE_TAG}
TAG="${CIRCLE_BRANCH//\//_}"
fi
DOCKER_TAG="ghcr.io/${CIRCLE_PROJECT_USERNAME,,}/${CIRCLE_PROJECT_REPONAME,,}:${TAG,,}"
if [[ -n "<< parameters.variant >>" ]]
then
Expand Down Expand Up @@ -188,24 +181,6 @@ jobs:
- combine-coverage
- store_artifacts:
path: htmlcov
push-release:
parameters:
variant:
type: string
default: ""
machine:
image: ubuntu-2004:202010-01
resource_class: medium
steps:
- checkout
- set-up-variant:
variant: "<< parameters.variant >>"
- attach_workspace:
at: /home/circleci/
- push-to-docker-hub:
tag: release-$CIRCLE_TAG
- push-to-docker-hub:
tag: latest
push-branch-to-docker-hub:
parameters:
variant:
Expand Down Expand Up @@ -284,12 +259,6 @@ workflows:
test:
jobs:
- combine-coverage:
filters: &tagged
branches:
ignore:
- main
tags:
only: /^v.*/
name: "Combine coverage"
requires:
- "Test in Docker"
Expand All @@ -304,8 +273,6 @@ workflows:
branches:
only:
- develop
tags:
ignore: /.*/
matrix:
parameters:
variant:
Expand All @@ -315,37 +282,21 @@ workflows:
- fMRIPrep-LTS
requires:
- "Combine coverage"
- push-release:
<<: *tagged
matrix:
parameters:
variant:
- ""
- lite
- ABCD-HCP
- fMRIPrep-LTS
- pytest-docker:
<<: *tagged
name: "Test in Docker"
- pytest-docker:
<<: *tagged
name: "Test ABCD-HCP variant in Docker"
variant: ABCD-HCP
- pytest-docker:
<<: *tagged
name: "Test fMRIPrep-LTS variant in Docker"
variant: fMRIPrep-LTS
- pytest-docker:
<<: *tagged
name: "Test lite variant in Docker"
- pytest-singularity:
<<: *tagged
name: "Test in Singularity"
- pytest-singularity:
<<: *tagged
name: "Test ABCD-HCP variant in Singularity"
variant: ABCD-HCP
- pytest-singularity:
<<: *tagged
name: "Test lite variant in Singularity"
variant: lite
2 changes: 1 addition & 1 deletion .github/workflows/build_C-PAC.yml
Expand Up @@ -26,7 +26,7 @@ jobs:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1.6.0
- name: Log in to GitHub Container Registry
uses: docker/login-action@v1
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
Expand Down
45 changes: 39 additions & 6 deletions .github/workflows/build_and_test.yml
Expand Up @@ -48,6 +48,7 @@ jobs:
- C-PAC-ABCD-HCP
- C-PAC-fMRIPrep-LTS
runs-on: ubuntu-latest
if: github.ref_name == 'develop' || github.ref_name == 'main'
steps:
- name: Check out C-PAC
uses: actions/checkout@v2
Expand Down Expand Up @@ -92,6 +93,7 @@ jobs:
- C-PAC-lite
- C-PAC-ABCD-HCP
- C-PAC-fMRIPrep-LTS
if: github.ref_type == 'branch'
runs-on: ubuntu-latest
steps:
- name: Check out C-PAC
Expand All @@ -103,12 +105,7 @@ jobs:
echo "ref: $GITHUB_REF_NAME"
TEXT="Triggered pipeline at "
U1="https://circleci.com/api/v2/project/gh/${GITHUB_REPOSITORY}/pipeline"
if [[ "${GITHUB_REF_TYPE}" == "tag" ]]
then
export DATA="{\"tag\":\"$GITHUB_REF_NAME\", \"parameters\": {\"run_tests\": true}}"
else
export DATA="{\"branch\":\"$GITHUB_REF_NAME\", \"parameters\": {\"run_tests\": true}}"
fi
export DATA="{\"branch\":\"$GITHUB_REF_NAME\", \"parameters\": {\"run_tests\": true}}"
echo "URL ${U1}"
echo "data ${DATA}"
PIPELINE_NUMBER=$(curl \
Expand All @@ -133,3 +130,39 @@ jobs:
jq '.items[0].id' |
tr -d '"')
echo ${TEXT}https://app.circleci.com/pipelines/github/${GITHUB_REPOSITORY}/${PIPELINE_NUMBER}/workflows/${WORKFLOW_ID}
Deploy_to_Docker_Hub:
needs:
- C-PAC
if: github.ref_type == 'tag'
uses: ./.github/workflows/deploy_to_Docker_Hub.yml
with:
variant: ''
secrets: inherit

Deploy_to_Docker_Hub-lite:
needs:
- C-PAC-lite
if: github.ref_type == 'tag'
uses: ./.github/workflows/deploy_to_Docker_Hub.yml
with:
variant: 'lite'
secrets: inherit

Deploy_to_Docker_Hub-ABCD-HCP:
needs:
- C-PAC-ABCD-HCP
if: github.ref_type == 'tag'
uses: ./.github/workflows/deploy_to_Docker_Hub.yml
with:
variant: 'ABCD-HCP'
secrets: inherit

Deploy_to_Docker_Hub-fMRIPrep-LTS:
needs:
- C-PAC-fMRIPrep-LTS
if: github.ref_type == 'tag'
uses: ./.github/workflows/deploy_to_Docker_Hub.yml
with:
variant: 'fMRIPrep-LTS'
secrets: inherit
6 changes: 3 additions & 3 deletions .github/workflows/build_stages.yml
Expand Up @@ -71,7 +71,7 @@ jobs:
uses: docker/setup-buildx-action@v1.6.0
if: contains(steps.changed-files-base.outputs.all_changed_files, matrix.Dockerfile) || contains(steps.changed-files.outputs.all_changed_files, matrix.Dockerfile)
- name: Log in to GitHub Container Registry
uses: docker/login-action@v1
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
Expand Down Expand Up @@ -143,7 +143,7 @@ jobs:
uses: docker/setup-buildx-action@v1.6.0
if: contains(steps.changed-files-base.outputs.all_changed_files, matrix.Dockerfile) || contains(steps.changed-files.outputs.all_changed_files, matrix.Dockerfile)
- name: Log in to GitHub Container Registry
uses: docker/login-action@v1
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
Expand Down Expand Up @@ -243,7 +243,7 @@ jobs:
uses: docker/setup-buildx-action@v1.6.0
if: always() && steps.changed-files-base.outputs.any_changed == 'true' || steps.changed-files.outputs.any_changed == 'true' || steps.docker_tag.not_yet_exists == 1
- name: Log in to GitHub Container Registry
uses: docker/login-action@v1
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
Expand Down
40 changes: 40 additions & 0 deletions .github/workflows/deploy_to_Docker_Hub.yml
@@ -0,0 +1,40 @@
name: Deploy to Docker Hub

on:
workflow_call:
inputs:
variant:
required: true
type: string
secrets:
DOCKERHUB_USER:
required: true
DOCKERHUB_TOKEN:
required: true

jobs:
Deploy_to_Docker_Hub:
name: Deploy to Docker Hub
runs-on: ubuntu-latest
steps:
- name: Log in to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USER }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Pull, tag and push
run: |
if [[ "${{ inputs.variant }}" != "" ]]
then
VARIANT=-${{ inputs.variant }}
fi
TAG1=latest$VARIANT
TAG2=release-${{ github.ref_name }}$VARIANT
DOCKER_TAG=$(echo "ghcr.io/${{ github.repository }}" | tr '[:upper:]' '[:lower:]')
echo "original tag: ${DOCKER_TAG}:${TAG1}"
echo "new tags: fcpindi/c-pac:${TAG1} fcpindi/c-pac:${TAG2}"
docker pull ${DOCKER_TAG}:${TAG1}
docker tag ${DOCKER_TAG}:${TAG1} fcpindi/c-pac:${TAG1}
docker tag ${DOCKER_TAG}:${TAG1} fcpindi/c-pac:${TAG2}
docker push fcpindi/c-pac:${TAG1}
docker push fcpindi/c-pac:${TAG2}

0 comments on commit 16f4781

Please sign in to comment.