-
Notifications
You must be signed in to change notification settings - Fork 0
/
build
executable file
·27 lines (21 loc) · 882 Bytes
/
build
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#!/bin/bash
source $(dirname "$0")/common
REGISTRY=ghcr.io
REGISTRY_USERNAME=${GITHUB_REPOSITORY%%/*}
IMAGE_NAME=${GITHUB_REPOSITORY#*/}
if [[ $ENV != production ]]; then
IMAGE_NAME=$IMAGE_NAME-$ENV
fi
IMAGE_ID=$(tr '[A-Z]' '[a-z]' <<< $REGISTRY/$REGISTRY_USERNAME/$IMAGE_NAME)
echo "IMAGE_ID=$IMAGE_ID" >> $GITHUB_ENV
log "Logging in to docker registry..."
echo "$REGISTRY_TOKEN" | docker login $REGISTRY -u $REGISTRY_USERNAME --password-stdin
log "Building $IMAGE_ID..."
if [[ "$DOCKERFILE" ]]; then
cp -r $DOCKERFILE/. .
fi
export DOCKER_BUILD_ARG_ENV=$ENV
DOCKER_BUILD_ARGS="$(env | (grep '^DOCKER_BUILD_ARG_' || :) | sed 's/^DOCKER_BUILD_ARG_/--build-arg /')"
docker pull $IMAGE_ID || true
docker buildx build . --tag $IMAGE_ID --cache-to type=inline --cache-from type=registry,ref=$IMAGE_ID $DOCKER_BUILD_ARGS $DOCKERFILE_ARG
log "Successfully built $IMAGE_ID."