diff --git a/.github/workflows/docker.yaml b/.github/workflows/docker.yaml new file mode 100644 index 0000000..5adecad --- /dev/null +++ b/.github/workflows/docker.yaml @@ -0,0 +1,46 @@ +name: Docker + +on: + push: + tags: + - 'v*' + branches: + - 'master' + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +jobs: + build-and-push-image: + runs-on: ubuntu-latest + + permissions: + contents: read + packages: write + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Log in to the Container registry + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + + - name: Build and push Docker image + uses: docker/build-push-action@v5 + with: + context: . + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + build-args: "VERSION=${GITHUB_REF##*/}" diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..0249373 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,29 @@ +# Step 1: Use the official Golang image as the build environment. +# This image includes all the tools needed to compile Go applications. +FROM golang:1.21 as builder + +# Version will be passed as a part of the build. +ARG VERSION=dev + +# Set the Current Working Directory inside the container. +WORKDIR /app + +# Copy the local package files to the container's workspace. +COPY . . + +# Build the Go app for a Linux system. The -o flag specifies the output binary +# name. +RUN VERSION=${VERSION} make build + +# Step 2: Use a Docker multi-stage build to create a lean production image. +# Start from a scratch (empty) image to keep the image size small. +FROM scratch + +# Copy the binary from the builder stage to the production image. +COPY --from=builder /app/udptlspipe / + +# Exact protocol depends on operation mode: tcp for server and udp for client. +EXPOSE 8443/tcp +EXPOSE 8443/udp + +ENTRYPOINT ["/udptlspipe", "-h"] \ No newline at end of file diff --git a/Makefile b/Makefile index e1bcc4d..2dfcdbc 100644 --- a/Makefile +++ b/Makefile @@ -17,7 +17,7 @@ endif default: build build: clean - go build -ldflags "-X $(VERSIONPKG).version=$(VERSION)" + CGO_ENABLED=0 go build -ldflags "-X $(VERSIONPKG).version=$(VERSION)" -o $(NAME) release: check-env-release mkdir -p $(BUILDDIR)