Improve website docker image build (#8437)

* improve website docker image build

* update image tag technique

* generate ci file
This commit is contained in:
Jeff Escalante 2020-03-06 13:50:38 -05:00 committed by GitHub
parent a9e864f5e3
commit 4019a3543c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 52 additions and 70 deletions

82
.circleci/config.yml generated
View File

@ -325,29 +325,19 @@ jobs:
- setup_remote_docker
- run:
command: |
# 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; \
)" || true
[ $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
IMAGE_TAG="$(git rev-list -n1 HEAD -- website/Dockerfile website/package-lock.json)"
echo "Using $IMAGE_TAG"
if [ "$CIRCLE_REPOSITORY_URL" != "git@github.com:hashicorp/vault" ]; then
echo "Not Vault OSS Repo, not building website docker image"
elif curl https://hub.docker.com/v2/repositories/hashicorp/vault-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/vault-website:$IMAGE_TAG .
docker tag hashicorp/vault-website:$IMAGE_TAG hashicorp/vault-website:latest
docker login -u $WEBSITE_DOCKER_USER -p $WEBSITE_DOCKER_PASS
docker push hashicorp/vault-website
fi
name: Build Docker Image if Necessary
workflows:
ci:
@ -382,6 +372,10 @@ workflows:
requires:
- build-go-dev
- website-docker-image:
filters:
branches:
only:
- master
context: vault-docs
version: 2
@ -650,29 +644,19 @@ workflows:
# - setup_remote_docker
# - run:
# command: |
# # 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; \\
# )\" || true
# [ $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
# IMAGE_TAG=\"$(git rev-list -n1 HEAD -- website/Dockerfile website/package-lock.json)\"
# echo \"Using $IMAGE_TAG\"
# if [ \"$CIRCLE_REPOSITORY_URL\" != \"git@github.com:hashicorp/vault\" ]; then
# echo \"Not Vault OSS Repo, not building website docker image\"
# elif curl https://hub.docker.com/v2/repositories/hashicorp/vault-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/vault-website:$IMAGE_TAG .
# docker tag hashicorp/vault-website:$IMAGE_TAG hashicorp/vault-website:latest
# docker login -u $WEBSITE_DOCKER_USER -p $WEBSITE_DOCKER_PASS
# docker push hashicorp/vault-website
# fi
# name: Build Docker Image if Necessary
# references:
# cache:
@ -714,4 +698,8 @@ workflows:
# requires:
# - build-go-dev
# - website-docker-image:
# context: vault-docs
# context: vault-docs
# filters:
# branches:
# only:
# - master

View File

@ -7,26 +7,16 @@ steps:
- run:
name: Build Docker Image if Necessary
command: |
# 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; \
)" || true
[ $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
IMAGE_TAG="$(git rev-list -n1 HEAD -- website/Dockerfile website/package-lock.json)"
echo "Using $IMAGE_TAG"
if [ "$CIRCLE_REPOSITORY_URL" != "git@github.com:hashicorp/vault" ]; then
echo "Not Vault OSS Repo, not building website docker image"
elif curl https://hub.docker.com/v2/repositories/hashicorp/vault-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/vault-website:$IMAGE_TAG .
docker tag hashicorp/vault-website:$IMAGE_TAG hashicorp/vault-website:latest
docker login -u $WEBSITE_DOCKER_USER -p $WEBSITE_DOCKER_PASS
docker push hashicorp/vault-website
fi

View File

@ -32,3 +32,7 @@ jobs:
- /^ui\/.*/
- website-docker-image:
context: vault-docs
filters:
branches:
only:
- master