diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..d371036 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,2 @@ +.env +.git diff --git a/.gitea/workflows/build.yaml b/.gitea/workflows/build.yaml new file mode 100644 index 0000000..8b9b87a --- /dev/null +++ b/.gitea/workflows/build.yaml @@ -0,0 +1,25 @@ +name: Build +on: + workflow_dispatch: + +jobs: + build: + runs-on: linux-arm64 + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Login to Gitea Registry + uses: docker/login-action@v3 + with: + registry: gitea.coupxd.com + username: ${{ secrets.REGISTRY_USER }} + password: ${{ secrets.REGISTRY_PASSWORD }} + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - name: Build and Push + uses: docker/build-push-action@v5 + with: + context: . + platforms: linux/arm64 + push: true + tags: gitea.coupxd.com/cody/go-weather:latest diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..33034df --- /dev/null +++ b/Dockerfile @@ -0,0 +1,12 @@ +FROM golang:1.23-bookworm AS builder +WORKDIR /app +COPY go.mod go.sum ./ +RUN go mod download +COPY . . +# Buildx automatically injects TARGETARCH, TARGETOS, and TARGETPLATFORM as build args into the Dockerfile +ARG TARGETARCH +RUN CGO_ENABLED=0 GOOS=linux GOARCH=${TARGETARCH} go build -o go-weather . +FROM gcr.io/distroless/static-debian12 +COPY --from=builder /app/go-weather /go-weather +EXPOSE 8080 +ENTRYPOINT ["/go-weather"] diff --git a/build.sh b/build.sh new file mode 100644 index 0000000..5b80a02 --- /dev/null +++ b/build.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +echo "Creating build environment" +docker buildx create --name pibuilder --use + +echo "Printing build environment info" +docker buildx inspect --bootstrap + +echo "Doing build" +docker buildx build \ + --platform linux/arm64 \ + --push \ + -t gitea.coupxd.com/cody/hello-fastapi:latest \ + . +