name: Docker Build description: Build a Docker image with tags inputs: image: description: Full image name (registry/org/name) required: true tags: description: Comma-separated list of tags default: 'latest' context: description: Build context path default: '.' dockerfile: description: Path to Dockerfile default: 'Dockerfile' build-args: description: Build arguments (KEY=value, newline-separated) default: '' outputs: images: description: Built image references value: ${{ steps.build.outputs.images }} runs: using: composite steps: - id: build shell: bash run: | IMAGE="${{ inputs.image }}" TAGS="${{ inputs.tags }}" CONTEXT="${{ inputs.context }}" DOCKERFILE="${{ inputs.dockerfile }}" BUILD_ARGS="${{ inputs.build-args }}" # Build tag arguments TAG_ARGS="" IMAGES="" IFS=',' read -ra TAG_ARRAY <<< "$TAGS" for tag in "${TAG_ARRAY[@]}"; do tag=$(echo "$tag" | xargs) # trim whitespace TAG_ARGS="$TAG_ARGS -t $IMAGE:$tag" IMAGES="$IMAGES$IMAGE:$tag," done IMAGES="${IMAGES%,}" # remove trailing comma # Build build-arg arguments BUILD_ARG_ARGS="" if [ -n "$BUILD_ARGS" ]; then while IFS= read -r arg; do if [ -n "$arg" ]; then BUILD_ARG_ARGS="$BUILD_ARG_ARGS --build-arg $arg" fi done <<< "$BUILD_ARGS" fi # Build the image docker build $TAG_ARGS $BUILD_ARG_ARGS -f "$DOCKERFILE" "$CONTEXT" echo "images=$IMAGES" >> $GITHUB_OUTPUT