From 5d62b70e90e8c9767fc565652d1e5626ae145c8e Mon Sep 17 00:00:00 2001 From: "Urko." Date: Sun, 5 May 2024 22:54:06 +0200 Subject: [PATCH] fix: load config --- Dockerfile | 34 ++++++++++++++++++++++++++++++++++ build.sh | 45 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+) create mode 100644 Dockerfile create mode 100755 build.sh diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..de2615a --- /dev/null +++ b/Dockerfile @@ -0,0 +1,34 @@ +# Start from the official Golang base image version 1.22 +FROM golang:1.22-alpine as builder + +# Set the Current Working Directory inside the container +WORKDIR /app + +# Copy go mod and sum files +COPY go.mod go.sum ./ + +# Download all dependencies. Dependencies will be cached if the go.mod and go.sum files are not changed +RUN go mod download + +# Copy the source code into the container +COPY . . + +# Build the Go app +RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o webhook-listener . + +# Start a new stage from scratch using a slim version of Alpine for a smaller image size +FROM alpine:latest + +WORKDIR /root/ + +# Copy the Pre-built binary file from the previous stage +COPY --from=builder /app/webhook-listener . + +# Environment variable for the port, set a default value if not provided +ENV PORT=62082 + +# Expose the port specified by the PORT environment variable +EXPOSE $PORT + +# Command to run the executable, modified to use the environment variable for the port +CMD ["./webhook-listener"] diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..79c5d9a --- /dev/null +++ b/build.sh @@ -0,0 +1,45 @@ +#!/bin/bash + +# Define variables +IMAGE_NAME="gitea-webhook-listener" +DOCKERFILE_PATH="./" +VERSION_FILE="version.txt" +REGISTRY="registry.fungimail.llc" +NAMESPACE="urko" + +# Version management +if [ ! -f "$VERSION_FILE" ]; then + echo "Version file not found, creating one with version 1..." + echo "1" > $VERSION_FILE +fi + +VERSION=$(cat $VERSION_FILE) +echo "Current version is $VERSION." + +# Increment the version +VERSION=$((VERSION+1)) +echo "Incrementing to new version $VERSION..." +echo $VERSION > $VERSION_FILE + +# Step 1: Build the Docker image with the new version tag +echo "Building Docker image $IMAGE_NAME:$VERSION..." +docker build -t $IMAGE_NAME:$VERSION $DOCKERFILE_PATH + +# Step 1b: Tag the image for the registry with version +FULL_IMAGE_NAME_VERSION="${REGISTRY}/${NAMESPACE}/${IMAGE_NAME}:${VERSION}" +echo "Tagging image for registry as $FULL_IMAGE_NAME_VERSION..." +docker tag $IMAGE_NAME:$VERSION $FULL_IMAGE_NAME_VERSION + +# Step 1c: Tag the image for the registry with 'latest' +FULL_IMAGE_NAME_LATEST="${REGISTRY}/${NAMESPACE}/${IMAGE_NAME}:latest" +echo "Tagging image for registry as $FULL_IMAGE_NAME_LATEST..." +docker tag $IMAGE_NAME:$VERSION $FULL_IMAGE_NAME_LATEST + +# Step 1d: Push the versioned image to the Docker registry +echo "Pushing $FULL_IMAGE_NAME_VERSION to the Docker registry..." +docker push $FULL_IMAGE_NAME_VERSION + +# Step 1e: Push the latest image to the Docker registry +echo "Pushing $FULL_IMAGE_NAME_LATEST to the Docker registry..." +docker push $FULL_IMAGE_NAME_LATEST +