Fixing dockerfile

This commit is contained in:
2024-11-24 12:56:28 +01:00
parent 6c641cb269
commit a6a9e3ebd1
3 changed files with 43 additions and 15 deletions

View File

@@ -1,10 +1,11 @@
FROM public.ecr.aws/docker/library/node:22-alpine3.20
# Install git for gitea actions and ansible
RUN apk add --no-cache git curl unzip docker-cli-buildx
RUN apk add --no-cache git curl unzip docker-cli-buildx bash
WORKDIR /usr/src
COPY entrypoint.sh .
ENTRYPOINT ["/usr/src/entrypoint.sh"]
RUN chmod +x /usr/src/entrypoint.sh
ENTRYPOINT ["bash","-c","/usr/src/entrypoint.sh"]

View File

@@ -10,8 +10,12 @@ inputs:
imagePrefix:
description: The image prefix
required: false
default: ${{ gitea.repositoryUrl }}/${{ gitea.repository_owner }}/
push:
default: ${{ gitea.server_url }}/${{ gitea.repository_owner }}/
path:
description: The dockerfile path
required: false
default: "."
pushImage:
description: Should push the built image
required: false
default: "true"
@@ -19,6 +23,10 @@ inputs:
description: Uses the pull cache
required: false
default: "true"
platform:
description: Comma separated list for building platform
required: false
default: ""
# Define your outputs here.
outputs:
@@ -31,5 +39,7 @@ runs:
env:
INPUT_IMAGE_NAME: ${{ inputs.imageName }}
INPUT_IMAGE_PREFIX: ${{ inputs.imagePrefix }}
INPUT_PUSH: ${{ inputs.push }}
INPUT_PUSH_IMAGE: ${{ inputs.pushImage }}
INPUT_PULL_CACHE: ${{ inputs.pullCache }}
INPUT_DOCKERFILE_PATH: ${{ inputs.path }}
INPUT_PLATFORM: ${{ inputs.platform }}

View File

@@ -1,28 +1,45 @@
#!/bin/sh -l
#!/usr/bin/env bash
IMAGE_NAME="$(echo "$INPUT_IMAGE_PREFIX" | sed 's/^https\?:\/\///')$INPUT_IMAGE_NAME"
set -e
echo "::notice file=entrypoint.sh,line=7::$IMAGE_NAME"
# shellcheck disable=SC2155
export LOWERCASE_INPUT_IMAGE_PREFIX="$(echo "$INPUT_IMAGE_PREFIX" | tr '[:upper:]' '[:lower:]')"
IMAGE_NAME="$(echo "$LOWERCASE_INPUT_IMAGE_PREFIX" | sed 's/^https\?:\/\///')$INPUT_IMAGE_NAME"
env
if [ -n "$DOCKER_CONFIG_BASE64" ]; then
echo "Retrieving docker config"
mkdir "$HOME/.docker/"
echo "$DOCKER_CONFIG_BASE64" | base64 -d > "$HOME/.docker/config.json"
fi;
echo "Full image name: $IMAGE_NAME"
if [ -z "$INPUT_IMAGE_NAME" ]; then
echo "No image name given."
exit 1
fi;
if [ "$INPUT_PUSH" = "true" ]; then
DOCKER_BUILD_OPTIONS="${DOCKER_BUILD_OPTIONS} --push"
DOCKER_BUILD_OPTIONS=("--progress" "plain" "-t" "$IMAGE_NAME")
if [ -n "$INPUT_PLATFORM" ]; then
DOCKER_BUILD_OPTIONS+=("--platform" "$INPUT_PLATFORM")
fi
if [ "$INPUT_PUSH_IMAGE" = "true" ]; then
DOCKER_BUILD_OPTIONS+=("--push")
fi
if [ "$INPUT_PULL_CACHE" = "true" ]; then
# shellcheck disable=SC2089
DOCKER_BUILD_OPTIONS="${DOCKER_BUILD_OPTIONS} --cache-from \"$IMAGE_NAME\""
DOCKER_BUILD_OPTIONS+=("--cache-from" "$IMAGE_NAME")
echo "Pulling for cache"
docker pull "$1" || echo "No image found."
docker pull "$IMAGE_NAME" || echo "Unable to find an image to pull."
fi
# shellcheck disable=SC2145
echo "Running docker buildx with options: ${DOCKER_BUILD_OPTIONS[@]}"
echo "Building and pushing !"
# shellcheck disable=SC2090
docker buildx build ${DOCKER_BUILD_OPTIONS} -t "$IMAGE_NAME" --progress plain
docker buildx build DOCKER_BUILD_OPTIONS[@] "${INPUT_DOCKERFILE_PATH}"
echo "imageName=${IMAGE_NAME}" >>"$GITEA_OUTPUT"