ci: build website docker image only on OSS repo (#8335)

This commit is contained in:
Sam Salisbury 2020-02-11 17:03:54 +00:00 committed by GitHub
parent 7996b8f65a
commit 42faa3687c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 60 additions and 39 deletions

46
.circleci/config.yml generated
View File

@ -314,19 +314,26 @@ jobs:
- setup_remote_docker
- run:
command: |
echo 'export PACKAGE_LOCK_CHANGED=$(git diff --name-only $(git log --pretty=format:'%h' -n1 HEAD~1)...HEAD | grep -c website/package-lock.json)' >> $BASH_ENV
name: Diff package-lock.json
- run:
command: |
if [ "$CIRCLE_BRANCH" = "master" ] && [ $PACKAGE_LOCK_CHANGED -gt 0 ]; then
# BUILD_FROM_REPO should ALWAYS be the main OSS Vault repo URL.
BUILD_FROM_REPO=git@github.com:hashicorp/vault.git
[ "$CIRCLE_REPOSITORY_URL" = "$BUILD_FROM_REPO" ] || {
echo "Not building website docker image for repo '$CIRCLE_REPOSITORY_URL' - we only build it for $BUILD_FROM_REPO."
exit 0
}
[ "$CIRCLE_BRANCH" = "master" ] || {
echo "Not building website docker image for branch '$CIRCLE_BRANCH' - we only build it for master."
exit 0
}
PACKAGE_LOCK_CHANGED=$(git diff --name-only $(git log --pretty=format:'%h' -n1 HEAD~1)...HEAD | grep -c website/package-lock.json)
[ $PACKAGE_LOCK_CHANGED -gt 0 ] || {
echo "Not building a new website docker image - dependencies have not changed."
exit 0
}
cd website/
docker build -t hashicorp/vault-website:$CIRCLE_SHA1 .
docker tag hashicorp/vault-website:$CIRCLE_SHA1 hashicorp/vault-website:latest
docker login -u $DOCKER_USER -p $DOCKER_PASS
docker push hashicorp/vault-website
else
echo "Not building a new website docker image - branch is not master and/or dependencies have not changed."
fi
name: Build Docker Image if Necessary
workflows:
ci:
@ -608,19 +615,26 @@ workflows:
# - setup_remote_docker
# - run:
# command: |
# echo 'export PACKAGE_LOCK_CHANGED=$(git diff --name-only $(git log --pretty=format:'%h' -n1 HEAD~1)...HEAD | grep -c website/package-lock.json)' >> $BASH_ENV
# name: Diff package-lock.json
# - run:
# command: |
# if [ \"$CIRCLE_BRANCH\" = \"master\" ] && [ $PACKAGE_LOCK_CHANGED -gt 0 ]; then
# # BUILD_FROM_REPO should ALWAYS be the main OSS Vault repo URL.
# BUILD_FROM_REPO=git@github.com:hashicorp/vault.git
# [ \"$CIRCLE_REPOSITORY_URL\" = \"$BUILD_FROM_REPO\" ] || {
# echo \"Not building website docker image for repo '$CIRCLE_REPOSITORY_URL' - we only build it for $BUILD_FROM_REPO.\"
# exit 0
# }
# [ \"$CIRCLE_BRANCH\" = \"master\" ] || {
# echo \"Not building website docker image for branch '$CIRCLE_BRANCH' - we only build it for master.\"
# exit 0
# }
# PACKAGE_LOCK_CHANGED=$(git diff --name-only $(git log --pretty=format:'%h' -n1 HEAD~1)...HEAD | grep -c website/package-lock.json)
# [ $PACKAGE_LOCK_CHANGED -gt 0 ] || {
# echo \"Not building a new website docker image - dependencies have not changed.\"
# exit 0
# }
# cd website/
# docker build -t hashicorp/vault-website:$CIRCLE_SHA1 .
# docker tag hashicorp/vault-website:$CIRCLE_SHA1 hashicorp/vault-website:latest
# docker login -u $DOCKER_USER -p $DOCKER_PASS
# docker push hashicorp/vault-website
# else
# echo \"Not building a new website docker image - branch is not master and/or dependencies have not changed.\"
# fi
# name: Build Docker Image if Necessary
# references:
# cache:

View File

@ -4,19 +4,26 @@ shell: /usr/bin/env bash -euo pipefail -c
steps:
- checkout
- setup_remote_docker
- run:
name: Diff package-lock.json
command: |
echo 'export PACKAGE_LOCK_CHANGED=$(git diff --name-only $(git log --pretty=format:'%h' -n1 HEAD~1)...HEAD | grep -c website/package-lock.json)' >> $BASH_ENV
- run:
name: Build Docker Image if Necessary
command: |
if [ "$CIRCLE_BRANCH" = "master" ] && [ $PACKAGE_LOCK_CHANGED -gt 0 ]; then
# BUILD_FROM_REPO should ALWAYS be the main OSS Vault repo URL.
BUILD_FROM_REPO=git@github.com:hashicorp/vault.git
[ "$CIRCLE_REPOSITORY_URL" = "$BUILD_FROM_REPO" ] || {
echo "Not building website docker image for repo '$CIRCLE_REPOSITORY_URL' - we only build it for $BUILD_FROM_REPO."
exit 0
}
[ "$CIRCLE_BRANCH" = "master" ] || {
echo "Not building website docker image for branch '$CIRCLE_BRANCH' - we only build it for master."
exit 0
}
PACKAGE_LOCK_CHANGED=$(git diff --name-only $(git log --pretty=format:'%h' -n1 HEAD~1)...HEAD | grep -c website/package-lock.json)
[ $PACKAGE_LOCK_CHANGED -gt 0 ] || {
echo "Not building a new website docker image - dependencies have not changed."
exit 0
}
cd website/
docker build -t hashicorp/vault-website:$CIRCLE_SHA1 .
docker tag hashicorp/vault-website:$CIRCLE_SHA1 hashicorp/vault-website:latest
docker login -u $DOCKER_USER -p $DOCKER_PASS
docker push hashicorp/vault-website
else
echo "Not building a new website docker image - branch is not master and/or dependencies have not changed."
fi