From 974b74d306040ee9032bd3fb2620b52d3c28a6f3 Mon Sep 17 00:00:00 2001 From: Drew Bailey <2614075+drewbailey@users.noreply.github.com> Date: Wed, 19 Feb 2020 09:18:43 -0500 Subject: [PATCH 1/3] check if website-docker-image job should run --- .circleci/config.yml | 23 +++++++++++-------- .../config/jobs/website-docker-image.yml | 23 +++++++++++-------- 2 files changed, 26 insertions(+), 20 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index e3ed70249..4884549e7 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -455,16 +455,19 @@ jobs: # There is an edge case that would cause an issue here - if dependencies are updated to an exact copy # of a previous version, for example if packge-lock.json is reverted, we need to manually push the new # image to the "latest" tag - IMAGE_TAG=$(cat website/Dockerfile website/package-lock.json | sha256sum | awk '{print $1;}') - echo "Using $IMAGE_TAG" - if ! curl https://hub.docker.com/v2/repositories/hashicorp/nomad-website/tags/$IMAGE_TAG -fsL > /dev/null; then - cd website/ - docker build -t hashicorp/nomad-website:$IMAGE_TAG . - docker tag hashicorp/nomad-website:$IMAGE_TAG hashicorp/nomad-website:latest - docker login -u $WEBSITE_DOCKER_USER -p $WEBSITE_DOCKER_PASS - docker push hashicorp/nomad-website - else - echo "Dependencies have not changed, not building a new website docker image." + # Ignore job if running an enterprise build + if ! [ "$NOMAD_ENT_BUILD" = "true" ]; then + IMAGE_TAG=$(cat website/Dockerfile website/package-lock.json | sha256sum | awk '{print $1;}') + echo "Using $IMAGE_TAG" + if ! curl https://hub.docker.com/v2/repositories/hashicorp/nomad-website/tags/$IMAGE_TAG -fsL > /dev/null; then + cd website/ + docker build -t hashicorp/nomad-website:$IMAGE_TAG . + docker tag hashicorp/nomad-website:$IMAGE_TAG hashicorp/nomad-website:latest + docker login -u $WEBSITE_DOCKER_USER -p $WEBSITE_DOCKER_PASS + docker push hashicorp/nomad-website + else + echo "Dependencies have not changed, not building a new website docker image." + fi fi name: Build Docker Image if Necessary test-other: diff --git a/.circleci/config/jobs/website-docker-image.yml b/.circleci/config/jobs/website-docker-image.yml index f73386ffc..eba749c64 100644 --- a/.circleci/config/jobs/website-docker-image.yml +++ b/.circleci/config/jobs/website-docker-image.yml @@ -10,14 +10,17 @@ steps: # There is an edge case that would cause an issue here - if dependencies are updated to an exact copy # of a previous version, for example if packge-lock.json is reverted, we need to manually push the new # image to the "latest" tag - IMAGE_TAG=$(cat website/Dockerfile website/package-lock.json | sha256sum | awk '{print $1;}') - echo "Using $IMAGE_TAG" - if ! curl https://hub.docker.com/v2/repositories/hashicorp/nomad-website/tags/$IMAGE_TAG -fsL > /dev/null; then - cd website/ - docker build -t hashicorp/nomad-website:$IMAGE_TAG . - docker tag hashicorp/nomad-website:$IMAGE_TAG hashicorp/nomad-website:latest - docker login -u $WEBSITE_DOCKER_USER -p $WEBSITE_DOCKER_PASS - docker push hashicorp/nomad-website - else - echo "Dependencies have not changed, not building a new website docker image." + # Ignore job if running an enterprise build + if ! [ "$NOMAD_ENT_BUILD" = "true" ]; then + IMAGE_TAG=$(cat website/Dockerfile website/package-lock.json | sha256sum | awk '{print $1;}') + echo "Using $IMAGE_TAG" + if ! curl https://hub.docker.com/v2/repositories/hashicorp/nomad-website/tags/$IMAGE_TAG -fsL > /dev/null; then + cd website/ + docker build -t hashicorp/nomad-website:$IMAGE_TAG . + docker tag hashicorp/nomad-website:$IMAGE_TAG hashicorp/nomad-website:latest + docker login -u $WEBSITE_DOCKER_USER -p $WEBSITE_DOCKER_PASS + docker push hashicorp/nomad-website + else + echo "Dependencies have not changed, not building a new website docker image." + fi fi From ea5229e2cfb9bd77ae1b9d06e4168dd77bb8e49c Mon Sep 17 00:00:00 2001 From: Drew Bailey <2614075+drewbailey@users.noreply.github.com> Date: Wed, 19 Feb 2020 12:44:22 -0500 Subject: [PATCH 2/3] refact to remove conditional nesting --- .circleci/config/jobs/website-docker-image.yml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/.circleci/config/jobs/website-docker-image.yml b/.circleci/config/jobs/website-docker-image.yml index eba749c64..207f591bb 100644 --- a/.circleci/config/jobs/website-docker-image.yml +++ b/.circleci/config/jobs/website-docker-image.yml @@ -11,16 +11,16 @@ steps: # of a previous version, for example if packge-lock.json is reverted, we need to manually push the new # image to the "latest" tag # Ignore job if running an enterprise build - if ! [ "$NOMAD_ENT_BUILD" = "true" ]; then - IMAGE_TAG=$(cat website/Dockerfile website/package-lock.json | sha256sum | awk '{print $1;}') - echo "Using $IMAGE_TAG" - if ! curl https://hub.docker.com/v2/repositories/hashicorp/nomad-website/tags/$IMAGE_TAG -fsL > /dev/null; then + IMAGE_TAG=$(cat website/Dockerfile website/package-lock.json | sha256sum | awk '{print $1;}') + echo "Using $IMAGE_TAG" + if [ "$CIRCLE_REPOSITORY_URL" != "git@github.com:hashicorp/nomad" ]; then + echo "Not Nomad OSS Repo, not building website docker image" + elif curl https://hub.docker.com/v2/repositories/hashicorp/nomad-website/tags/$IMAGE_TAG -fsL > /dev/null; then + echo "Dependencies have not changed, not building a new website docker image." + else cd website/ docker build -t hashicorp/nomad-website:$IMAGE_TAG . docker tag hashicorp/nomad-website:$IMAGE_TAG hashicorp/nomad-website:latest docker login -u $WEBSITE_DOCKER_USER -p $WEBSITE_DOCKER_PASS docker push hashicorp/nomad-website - else - echo "Dependencies have not changed, not building a new website docker image." - fi fi From b4e291c2eae2fd9c1c22bfdad36805e0e30e043b Mon Sep 17 00:00:00 2001 From: Drew Bailey <2614075+drewbailey@users.noreply.github.com> Date: Wed, 19 Feb 2020 12:44:47 -0500 Subject: [PATCH 3/3] make config.yml --- .circleci/config.yml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 4884549e7..539567c9a 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -456,18 +456,18 @@ jobs: # of a previous version, for example if packge-lock.json is reverted, we need to manually push the new # image to the "latest" tag # Ignore job if running an enterprise build - if ! [ "$NOMAD_ENT_BUILD" = "true" ]; then - IMAGE_TAG=$(cat website/Dockerfile website/package-lock.json | sha256sum | awk '{print $1;}') - echo "Using $IMAGE_TAG" - if ! curl https://hub.docker.com/v2/repositories/hashicorp/nomad-website/tags/$IMAGE_TAG -fsL > /dev/null; then + IMAGE_TAG=$(cat website/Dockerfile website/package-lock.json | sha256sum | awk '{print $1;}') + echo "Using $IMAGE_TAG" + if [ "$CIRCLE_REPOSITORY_URL" != "git@github.com:hashicorp/nomad" ]; then + echo "Not Nomad OSS Repo, not building website docker image" + elif curl https://hub.docker.com/v2/repositories/hashicorp/nomad-website/tags/$IMAGE_TAG -fsL > /dev/null; then + echo "Dependencies have not changed, not building a new website docker image." + else cd website/ docker build -t hashicorp/nomad-website:$IMAGE_TAG . docker tag hashicorp/nomad-website:$IMAGE_TAG hashicorp/nomad-website:latest docker login -u $WEBSITE_DOCKER_USER -p $WEBSITE_DOCKER_PASS docker push hashicorp/nomad-website - else - echo "Dependencies have not changed, not building a new website docker image." - fi fi name: Build Docker Image if Necessary test-other: