stick to one variable style
This commit is contained in:
parent
370a321bc1
commit
6782c6bcca
1 changed files with 15 additions and 15 deletions
30
buildx.sh
30
buildx.sh
|
@ -4,8 +4,8 @@
|
||||||
# accessing an uninitialized variable and print commands before executing them
|
# accessing an uninitialized variable and print commands before executing them
|
||||||
set -euxo pipefail
|
set -euxo pipefail
|
||||||
|
|
||||||
EVENT=$1
|
EVENT="$1"
|
||||||
IMAGE=$2
|
IMAGE="$2"
|
||||||
EDGE=false
|
EDGE=false
|
||||||
[ "$3" = edge ] && EDGE=true
|
[ "$3" = edge ] && EDGE=true
|
||||||
|
|
||||||
|
@ -32,27 +32,27 @@ push_image() {
|
||||||
|
|
||||||
docker_login() {
|
docker_login() {
|
||||||
printenv DOCKER_PASSWORD | docker login \
|
printenv DOCKER_PASSWORD | docker login \
|
||||||
--username "$DOCKER_USERNAME" \
|
--username "${DOCKER_USERNAME}" \
|
||||||
--password-stdin
|
--password-stdin
|
||||||
}
|
}
|
||||||
|
|
||||||
is_image_push_required() {
|
is_image_push_required() {
|
||||||
[ "$EVENT" != pull_request ] && { \
|
[ "${EVENT}" != pull_request ] && { \
|
||||||
[ "$GITHUB_REF" != refs/heads/master ] || \
|
[ "${GITHUB_REF}" != refs/heads/master ] || \
|
||||||
[ "$EVENT" = schedule ]
|
[ "${EVENT}" = schedule ]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
main() {
|
main() {
|
||||||
local TAG BUILD_ARGS
|
local TAG BUILD_ARGS IMAGE_TAGS
|
||||||
|
|
||||||
if [ "$EVENT" = schedule ] ; then
|
if [ "${EVENT}" = schedule ] ; then
|
||||||
TAG=nightly
|
TAG=nightly
|
||||||
else
|
else
|
||||||
TAG=${GITHUB_REF##*/}
|
TAG=${GITHUB_REF##*/}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
case "$IMAGE" in
|
case "${IMAGE}" in
|
||||||
fs)
|
fs)
|
||||||
BUILD_ARGS="--build-arg ALPINE_PACKAGES= --build-arg COMPOSER_PACKAGES="
|
BUILD_ARGS="--build-arg ALPINE_PACKAGES= --build-arg COMPOSER_PACKAGES="
|
||||||
;;
|
;;
|
||||||
|
@ -72,7 +72,7 @@ main() {
|
||||||
IMAGE="privatebin/${IMAGE}:"
|
IMAGE="privatebin/${IMAGE}:"
|
||||||
IMAGE_TAGS="--tag ${IMAGE}latest --tag ${IMAGE}${TAG} --tag ${IMAGE}${TAG%%-*}"
|
IMAGE_TAGS="--tag ${IMAGE}latest --tag ${IMAGE}${TAG} --tag ${IMAGE}${TAG%%-*}"
|
||||||
|
|
||||||
if [ "$EDGE" = true ] ; then
|
if [ "${EDGE}" = true ] ; then
|
||||||
# build from alpine:edge instead of the stable release
|
# build from alpine:edge instead of the stable release
|
||||||
sed -e 's/^FROM alpine:.*$/FROM alpine:edge/' Dockerfile > Dockerfile.edge
|
sed -e 's/^FROM alpine:.*$/FROM alpine:edge/' Dockerfile > Dockerfile.edge
|
||||||
BUILD_ARGS+=" -f Dockerfile.edge"
|
BUILD_ARGS+=" -f Dockerfile.edge"
|
||||||
|
@ -81,15 +81,15 @@ main() {
|
||||||
IMAGE_TAGS="--tag ${IMAGE}edge"
|
IMAGE_TAGS="--tag ${IMAGE}edge"
|
||||||
IMAGE+="edge"
|
IMAGE+="edge"
|
||||||
else
|
else
|
||||||
if [ "$EVENT" = push ] ; then
|
if [ "${EVENT}" = push ] ; then
|
||||||
# append the stable tag on explicit pushes to master or (git) tags
|
# append the stable tag on explicit pushes to master or (git) tags
|
||||||
IMAGE_TAGS+=" --tag ${IMAGE}stable"
|
IMAGE_TAGS+=" --tag ${IMAGE}stable"
|
||||||
fi
|
fi
|
||||||
IMAGE+="latest"
|
IMAGE+="latest"
|
||||||
fi
|
fi
|
||||||
build_image "$BUILD_ARGS $IMAGE_TAGS"
|
build_image "${BUILD_ARGS} ${IMAGE_TAGS}"
|
||||||
|
|
||||||
docker run -d --rm -p 127.0.0.1:8080:8080 --read-only --name smoketest "$IMAGE"
|
docker run -d --rm -p 127.0.0.1:8080:8080 --read-only --name smoketest "${IMAGE}"
|
||||||
sleep 5 # give the services time to start up and the log to collect any errors that might occur
|
sleep 5 # give the services time to start up and the log to collect any errors that might occur
|
||||||
test "$(docker inspect --format="{{.State.Running}}" smoketest)" = true
|
test "$(docker inspect --format="{{.State.Running}}" smoketest)" = true
|
||||||
curl --silent --show-error -o /dev/null http://127.0.0.1:8080/
|
curl --silent --show-error -o /dev/null http://127.0.0.1:8080/
|
||||||
|
@ -101,10 +101,10 @@ main() {
|
||||||
|
|
||||||
if is_image_push_required ; then
|
if is_image_push_required ; then
|
||||||
docker_login
|
docker_login
|
||||||
push_image "$BUILD_ARGS"
|
push_image "${BUILD_ARGS}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
rm -f Dockerfile.edge "$HOME/.docker/config.json"
|
rm -f Dockerfile.edge "${HOME}/.docker/config.json"
|
||||||
}
|
}
|
||||||
|
|
||||||
[ "$(basename "$0")" = 'buildx.sh' ] && main
|
[ "$(basename "$0")" = 'buildx.sh' ] && main
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue