diff --git a/.gitea/workflows/release.yaml b/.gitea/workflows/release.yaml new file mode 100644 index 0000000..66fba51 --- /dev/null +++ b/.gitea/workflows/release.yaml @@ -0,0 +1,30 @@ +name: Build docker container +on: + push: + branches: + - main + +jobs: + build: + name: Build image + runs-on: ubuntu-latest + container: ghcr.io/catthehacker/ubuntu:act-latest + env: + IMAGE_NAME: ip-svc + REGISTRY: git.mzsl.nl + REPO_OWNER: mans + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + registry: git.mzsl.nl + username: ${{ secrets.LOGIN_USER }} + password: ${{ secrets.LOGIN_PASS }} + - name: Build and push + run: | + TODAY=$(date +'%Y-%m-%d') + docker build -t ${REGISTRY}/${REPO_OWNER}/${IMAGE_NAME}:${TODAY} -t ${REGISTRY}/${REPO_OWNER}/${IMAGE_NAME}:latest . + docker push ${REGISTRY}/${REPO_OWNER}/${IMAGE_NAME}:${TODAY} + docker push ${REGISTRY}/${REPO_OWNER}/${IMAGE_NAME}:latest diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..e005303 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,33 @@ +# Stage 1: Build the Go application +FROM golang:1.22 AS builder + +# Set the Current Working Directory inside the container +WORKDIR /app + +# Copy go mod and sum files +COPY go.mod ./ + +# 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 GOARCH=amd64 go build -a -installsuffix cgo -o server . + +# Stage 2: Create a small image with just the compiled binary +FROM alpine:latest + +# Set the Current Working Directory inside the container +WORKDIR /root/ + +# Copy the pre-built binary file from the previous stage +COPY --from=builder /app/server . + +# Expose the port that the application will run on +EXPOSE 8080 + +# Command to run the executable +CMD ["./server"] + diff --git a/compose.yml b/compose.yml new file mode 100644 index 0000000..a3926cc --- /dev/null +++ b/compose.yml @@ -0,0 +1,45 @@ +services: + + traefik: + image: "traefik:v3.0" + container_name: "traefik" + command: + #- "--log.level=DEBUG" + - "--api.insecure=true" + - "--providers.docker=true" + - "--providers.docker.exposedbydefault=false" + - "--entryPoints.web.address=:80" + ports: + - "80:80" + - "8090:8080" + volumes: + - "/var/run/docker.sock:/var/run/docker.sock:ro" + networks: + - test + + whoami: + image: "traefik/whoami" + container_name: "simple-service" + labels: + - "traefik.enable=true" + - "traefik.http.routers.whoami.rule=Path(`/`)" + - "traefik.http.routers.whoami.entrypoints=web" + networks: + - test + + ip-svc: + build: . + container_name: "ip-svc" + labels: + - "traefik.enable=true" + - "traefik.http.routers.ip-svc.rule=Path(`/`) || Path(`/api`)" + - "traefik.http.routers.ip-svc.entrypoints=web" + networks: + - test + +networks: + test: + enable_ipv6: true + driver: bridge + default: +