31 lines
863 B
Shell
Executable file
31 lines
863 B
Shell
Executable file
#!/bin/bash
|
|
|
|
REGISTRY_URL=$(printenv INPUT_REGISTRY-URL)
|
|
USER=$(printenv INPUT_REGISTRY-USER)
|
|
IMAGE=$(printenv INPUT_IMAGE-NAME)
|
|
# fallback to registry variable
|
|
IMAGE=${IMAGE:-$FORGEJO_REPOSITORY}
|
|
TAG="$INPUT_TAG"
|
|
TOKEN="$INPUT_TOKEN"
|
|
CONTEXT="$GITHUB_WORKSPACE/$INPUT_CONTEXT"
|
|
|
|
# strip https:// from the registry url
|
|
if ! [[ "$REGISTRY_URL" =~ ^https:// ]]; then
|
|
echo "Only https registry urls are supported now. Provided registry url: $REGISTRY_URL"
|
|
exit 1
|
|
fi
|
|
REGISTRY=$(echo $REGISTRY_URL | sed -e 's/^https:\/\///g')
|
|
|
|
# build the image
|
|
IMAGE_TAG="$REGISTRY/$IMAGE:$TAG"
|
|
echo "Building the image, tag=$IMAGE_TAG"
|
|
docker build --compress --tag $IMAGE_TAG $CONTEXT
|
|
|
|
# log in the registry
|
|
printenv TOKEN | docker login -u $USER --password-stdin $REGISTRY_URL
|
|
|
|
# push the image
|
|
docker push $IMAGE_TAG
|
|
|
|
# log out of the registry
|
|
docker logout $REGISTRY_URL
|