From 862d426c71783e3a8cb3e1cb7c2cbe0c1064341b Mon Sep 17 00:00:00 2001 From: Danny Brown Date: Tue, 22 Oct 2019 15:53:44 -0400 Subject: [PATCH] ci: first attempt at adding a gated docker PR Publish (#1038) (#1041) * ci: first attempt at adding a gated docker PR Publish (#1038) * ci: first attempt at adding a gated docker PR Publish * See if we can use contexts to inject variables after approval * fix build command * try alternative context * docs: pull request template that spells out PR checklist * change context back to Docker Hub * Switch optional approval to another workflow * Make docker builds faster * Update .github/PULL_REQUEST_TEMPLATE/pull_request_template.md --- .circleci/config.yml | 52 ++++++++++++++++++- .../pull_request_template.md | 29 +++++++++++ Dockerfile | 1 + 3 files changed, 80 insertions(+), 2 deletions(-) create mode 100644 .github/PULL_REQUEST_TEMPLATE/pull_request_template.md diff --git a/.circleci/config.yml b/.circleci/config.yml index 51c986e61..19022c36f 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -198,7 +198,7 @@ jobs: - run: chmod +x ~/repo/.circleci/build-and-publish-docs.sh - run: ~/repo/.circleci/build-and-publish-docs.sh - DOCKER_PUBLISH: + DOCKER_MASTER_PUBLISH: <<: *defaults steps: - attach_workspace: @@ -227,6 +227,43 @@ jobs: docker push ohif/$IMAGE_NAME:latest fi + DOCKER_PR_PUBLISH: + <<: *defaults + steps: + # Enable yarn workspaces + - run: yarn config set workspaces-experimental true + + # Checkout code and ALL Git Tags + - checkout: + post: + - git fetch --all + + - restore_cache: + name: Restore Yarn and Cypress Package Cache + keys: + # when lock file changes, use increasingly general patterns to restore cache + - yarn-packages-{{ checksum "yarn.lock" }} + - yarn-packages- + + - run: + name: Install Dependencies + command: yarn install --frozen-lockfile + + - setup_remote_docker: + docker_layer_caching: false + + - run: + name: Build and push Docker image + command: | + # Remove npm config + rm -f ./.npmrc + # Set our version number using vars + echo $CIRCLE_BUILD_NUM + # Build our image, auth, and push + docker build --tag ohif/viewer:PR_BUILD-$CIRCLE_BUILD_NUM . + echo $DOCKER_PWD | docker login -u $DOCKER_LOGIN --password-stdin + docker push ohif/viewer:PR_BUILD-$CIRCLE_BUILD_NUM + VIEWER_DEMO_BUILD: <<: *defaults steps: @@ -331,6 +368,17 @@ workflows: requires: - UNIT_TESTS + PR_OPTIONAL_DOCKER_PUBLISH: + jobs: + # https://circleci.com/docs/2.0/workflows/#holding-a-workflow-for-a-manual-approval + - AWAIT_APPROVAL: + type: approval + # Update hub.docker.org + - DOCKER_PR_PUBLISH: + context: Docker Hub + requires: + - AWAIT_APPROVAL + # MERGE TO MASTER RELEASE: jobs: @@ -407,6 +455,6 @@ workflows: requires: - VIEWER_DEMO_BUILD # Update hub.docker.org - - DOCKER_PUBLISH: + - DOCKER_MASTER_PUBLISH: requires: - NPM_PUBLISH diff --git a/.github/PULL_REQUEST_TEMPLATE/pull_request_template.md b/.github/PULL_REQUEST_TEMPLATE/pull_request_template.md new file mode 100644 index 000000000..d74eb364c --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE/pull_request_template.md @@ -0,0 +1,29 @@ +### Request Checklist + +- [] Brief description of changes +- [] Links to any relevant issues +- [] Required status checks are passing +- [] `@mention` a maintainer to request a review + +#### Special + +> If this PR is not on a branch for this repo, it is "untrusted" and does not +> have access to env vars. Reviewers can kick off a trusted docker deploy by: +> +> 1. Verifying there are no malicious changes to CI build +> 2. Using the [git-push-fork-to-upstream-branch][script] script +> 3. Executing the manual approval step in the CI workflow + +- [] Request docker publish of PR + +_Want to improve this process? Consider PR'ing the ability for reviewers to add +a label to trigger this process._ + + + + +[blog]: https://circleci.com/blog/triggering-trusted-ci-jobs-on-untrusted-forks/ +[script]: https://github.com/jklukas/git-push-fork-to-upstream-branch + diff --git a/Dockerfile b/Dockerfile index faa58439b..f989e6881 100644 --- a/Dockerfile +++ b/Dockerfile @@ -44,6 +44,7 @@ RUN yarn config set workspaces-experimental true RUN yarn install ENV PATH /usr/src/app/node_modules/.bin:$PATH +ENV QUICK_BUILD true # ENV GENERATE_SOURCEMAP=false # ENV REACT_APP_CONFIG=config/default.js