diff --git a/.github/workflows/build-docker-images.yaml b/.github/workflows/build-docker-images.yaml index 0aede90..2b31bb9 100644 --- a/.github/workflows/build-docker-images.yaml +++ b/.github/workflows/build-docker-images.yaml @@ -10,7 +10,6 @@ on: env: REGISTRY: ghcr.io IMAGE_NAME: ${{ github.repository }} - BUILDCACHE_TAG: ghcr.io/sensorbucket/gacache:${{ github.sha }} jobs: test: @@ -48,26 +47,22 @@ jobs: matrix: include: - image: sensorbucket/httpimporter - dockerfile: services/httpimporter/Dockerfile - context: . + service: httpimporter - image: sensorbucket/core - dockerfile: services/core/Dockerfile - context: . + service: core - image: sensorbucket/tracing - dockerfile: services/tracing/Dockerfile - context: . + service: tracing - image: sensorbucket/dashboard - dockerfile: services/dashboard/Dockerfile - context: . + service: dashboard - image: sensorbucket/tenants - dockerfile: services/tenants/Dockerfile - context: . + service: tenants - image: sensorbucket/fission-user-workers - dockerfile: services/fission-user-workers/Dockerfile - context: . + service: fission-user-workers - image: sensorbucket/fission-rmq-connector - dockerfile: services/fission-rmq-connector/Dockerfile - context: . + service: fission-rmq-connector + platform: + - linux/amd64 + - linux/arm64 steps: - name: Checkout Repository @@ -102,13 +97,17 @@ jobs: - name: Build and push uses: docker/build-push-action@v5 with: - context: ${{ matrix.context }} - file: ${{ matrix.dockerfile }} + context: . + file: Dockerfile push: true - platforms: linux/amd64,linux/arm64 + platforms: ${{ matrix.platform }} tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} cache-from: | - type=registry,ref=${{ env.REGISTRY }}/${{ matrix.image }}:buildcache + type=registry,ref=${{ env.REGISTRY }}/${{ matrix.image }}:buildcache-${{ matrix.platform }} cache-to: | - type=registry,ref=${{ env.REGISTRY }}/${{ matrix.image }}:buildcache,mode=max + type=registry,ref=${{ env.REGISTRY }}/${{ matrix.image }}:buildcache-${{ matrix.platform }},mode=max + build-args: | + SERVICE_NAME=${{ matrix.service }} + TARGETOS=linux + TARGETARCH=${{ endsWith(matrix.platform, 'arm64') && 'arm64' || 'amd64' }} diff --git a/services/core/Dockerfile b/services/core/Dockerfile index 94f9df0..dbf551a 100644 --- a/services/core/Dockerfile +++ b/services/core/Dockerfile @@ -1,13 +1,43 @@ +# Build stage FROM golang:1.21-alpine AS builder -WORKDIR /sensorbucket -COPY go.mod . -COPY go.sum . +# Set working directory +WORKDIR /app + +# Install build dependencies +RUN apk add --no-cache git ca-certificates tzdata + +# Copy go mod and sum files +COPY go.mod go.sum ./ + +# Download dependencies RUN go mod download +# Copy the source code COPY . . -RUN CGO_ENABLED=0 go build -ldflags '-extldflags "-static"' -tags timetzdata -o /core services/core/main.go +# Build the application +ARG TARGETOS=linux +ARG TARGETARCH=amd64 +RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build \ + -ldflags='-w -s -extldflags "-static"' \ + -tags timetzdata \ + -o /core \ + services/core/main.go + +# Final stage FROM scratch AS production + +WORKDIR / + +# Copy timezone data +COPY --from=builder /usr/share/zoneinfo /usr/share/zoneinfo +# Copy CA certificates +COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ +# Copy the binary from the builder stage COPY --from=builder /core /core +# Set timezone environment variable +ENV TZ=Etc/UTC + +# Run the binary ENTRYPOINT ["/core"] diff --git a/services/dashboard/Dockerfile b/services/dashboard/Dockerfile index e145b6d..cfeee23 100644 --- a/services/dashboard/Dockerfile +++ b/services/dashboard/Dockerfile @@ -1,27 +1,51 @@ -FROM golang:1.21-alpine AS dev -WORKDIR /workspace +# Build stage +FROM golang:1.21-alpine AS builder + +# Set working directory +WORKDIR /app -RUN go install github.com/cespare/reflex@latest RUN go install github.com/valyala/quicktemplate/qtc@latest RUN go install github.com/evanw/esbuild/cmd/esbuild@latest -RUN apk add make curl +RUN apk add --no-cache git ca-certificates tzdata make curl RUN curl -sLO https://github.com/tailwindlabs/tailwindcss/releases/download/v3.3.3/tailwindcss-linux-x64 \ && chmod +x tailwindcss-linux-x64 \ && mv tailwindcss-linux-x64 /usr/bin/tailwind \ && ln -s /usr/bin/tailwind /usr/bin/tailwindcss +# Copy go mod and sum files COPY go.mod go.sum ./ + +# Download dependencies RUN go mod download -CMD ["make", "watch-dashboard"] +# Copy the source code +COPY . . -FROM dev AS build -WORKDIR /workspace +RUN make -C services/dashboard build -COPY . . -RUN GOOS=linux go build -o /app/dashboard ./services/dashboard +# Build the application +ARG TARGETOS=linux +ARG TARGETARCH=amd64 +RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build \ + -ldflags='-w -s -extldflags "-static"' \ + -tags timetzdata \ + -o /dashboard \ + services/dashboard/main.go + +# Final stage +FROM scratch AS production + +WORKDIR / + +# Copy timezone data +COPY --from=builder /usr/share/zoneinfo /usr/share/zoneinfo +# Copy CA certificates +COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ +# Copy the binary from the builder stage +COPY --from=builder /dashboard /dashboard +# Set timezone environment variable +ENV TZ=Etc/UTC -FROM alpine AS production -COPY --from=build /app/dashboard /app/dashboard -ENTRYPOINT ["/app/dashboard"] +# Run the binary +ENTRYPOINT ["/dashboard"] diff --git a/services/fission-rmq-connector/Dockerfile b/services/fission-rmq-connector/Dockerfile index d71ac61..2226249 100644 --- a/services/fission-rmq-connector/Dockerfile +++ b/services/fission-rmq-connector/Dockerfile @@ -1,13 +1,43 @@ +# Build stage FROM golang:1.21-alpine AS builder -WORKDIR /sensorbucket -COPY go.mod . -COPY go.sum . +# Set working directory +WORKDIR /app + +# Install build dependencies +RUN apk add --no-cache git ca-certificates tzdata + +# Copy go mod and sum files +COPY go.mod go.sum ./ + +# Download dependencies RUN go mod download +# Copy the source code COPY . . -RUN CGO_ENABLED=0 go build -ldflags '-extldflags "-static"' -tags timetzdata -o /fission-rmq-connector services/fission-rmq-connector/main.go +# Build the application +ARG TARGETOS=linux +ARG TARGETARCH=amd64 +RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build \ + -ldflags='-w -s -extldflags "-static"' \ + -tags timetzdata \ + -o /fission-rmq-connector \ + services/fission-rmq-connector/main.go + +# Final stage FROM scratch AS production + +WORKDIR / + +# Copy timezone data +COPY --from=builder /usr/share/zoneinfo /usr/share/zoneinfo +# Copy CA certificates +COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ +# Copy the binary from the builder stage COPY --from=builder /fission-rmq-connector /fission-rmq-connector +# Set timezone environment variable +ENV TZ=Etc/UTC + +# Run the binary ENTRYPOINT ["/fission-rmq-connector"] diff --git a/services/fission-user-workers/Dockerfile b/services/fission-user-workers/Dockerfile index e1d6d58..f27090d 100644 --- a/services/fission-user-workers/Dockerfile +++ b/services/fission-user-workers/Dockerfile @@ -1,13 +1,43 @@ +# Build stage FROM golang:1.21-alpine AS builder -WORKDIR /sensorbucket -COPY go.mod . -COPY go.sum . +# Set working directory +WORKDIR /app + +# Install build dependencies +RUN apk add --no-cache git ca-certificates tzdata + +# Copy go mod and sum files +COPY go.mod go.sum ./ + +# Download dependencies RUN go mod download +# Copy the source code COPY . . -RUN CGO_ENABLED=0 go build -ldflags '-extldflags "-static"' -tags timetzdata -o /user-workers services/fission-user-workers/main.go +# Build the application +ARG TARGETOS=linux +ARG TARGETARCH=amd64 +RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build \ + -ldflags='-w -s -extldflags "-static"' \ + -tags timetzdata \ + -o /fission-user-workers \ + services/fission-user-workers/main.go + +# Final stage FROM scratch AS production -COPY --from=builder /user-workers /user-workers -ENTRYPOINT ["/user-workers"] + +WORKDIR / + +# Copy timezone data +COPY --from=builder /usr/share/zoneinfo /usr/share/zoneinfo +# Copy CA certificates +COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ +# Copy the binary from the builder stage +COPY --from=builder /fission-user-workers /fission-user-workers +# Set timezone environment variable +ENV TZ=Etc/UTC + +# Run the binary +ENTRYPOINT ["/fission-user-workers"] diff --git a/services/httpimporter/Dockerfile b/services/httpimporter/Dockerfile index 9ef2ed4..86e0587 100644 --- a/services/httpimporter/Dockerfile +++ b/services/httpimporter/Dockerfile @@ -1,13 +1,43 @@ +# Build stage FROM golang:1.21-alpine AS builder -WORKDIR /sensorbucket -COPY go.mod . -COPY go.sum . +# Set working directory +WORKDIR /app + +# Install build dependencies +RUN apk add --no-cache git ca-certificates tzdata + +# Copy go mod and sum files +COPY go.mod go.sum ./ + +# Download dependencies RUN go mod download +# Copy the source code COPY . . -RUN CGO_ENABLED=0 go build -ldflags '-extldflags "-static"' -tags timetzdata -o /httpimporter services/httpimporter/main.go +# Build the application +ARG TARGETOS=linux +ARG TARGETARCH=amd64 +RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build \ + -ldflags='-w -s -extldflags "-static"' \ + -tags timetzdata \ + -o /httpimporter \ + services/httpimporter/main.go + +# Final stage FROM scratch AS production + +WORKDIR / + +# Copy timezone data +COPY --from=builder /usr/share/zoneinfo /usr/share/zoneinfo +# Copy CA certificates +COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ +# Copy the binary from the builder stage COPY --from=builder /httpimporter /httpimporter +# Set timezone environment variable +ENV TZ=Etc/UTC + +# Run the binary ENTRYPOINT ["/httpimporter"] diff --git a/services/tenants/Dockerfile b/services/tenants/Dockerfile index 4ae2c51..8a4e5fc 100644 --- a/services/tenants/Dockerfile +++ b/services/tenants/Dockerfile @@ -1,27 +1,51 @@ -FROM golang:1.21-alpine AS dev -WORKDIR /workspace +# Build stage +FROM golang:1.21-alpine AS builder + +# Set working directory +WORKDIR /app -RUN go install github.com/cespare/reflex@latest RUN go install github.com/valyala/quicktemplate/qtc@latest RUN go install github.com/evanw/esbuild/cmd/esbuild@latest -RUN apk add make curl +RUN apk add --no-cache git ca-certificates tzdata make curl RUN curl -sLO https://github.com/tailwindlabs/tailwindcss/releases/download/v3.3.3/tailwindcss-linux-x64 \ && chmod +x tailwindcss-linux-x64 \ && mv tailwindcss-linux-x64 /usr/bin/tailwind \ && ln -s /usr/bin/tailwind /usr/bin/tailwindcss +# Copy go mod and sum files COPY go.mod go.sum ./ + +# Download dependencies RUN go mod download -CMD ["make", "watch-tenants"] +# Copy the source code +COPY . . -FROM dev AS build -WORKDIR /workspace +RUN make -C services/tenants build -COPY . . -RUN GOOS=linux go build -o /app/tenants ./services/tenants +# Build the application +ARG TARGETOS=linux +ARG TARGETARCH=amd64 +RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build \ + -ldflags='-w -s -extldflags "-static"' \ + -tags timetzdata \ + -o /tenants \ + services/tenants/main.go + +# Final stage +FROM scratch AS production + +WORKDIR / + +# Copy timezone data +COPY --from=builder /usr/share/zoneinfo /usr/share/zoneinfo +# Copy CA certificates +COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ +# Copy the binary from the builder stage +COPY --from=builder /tenants /tenants +# Set timezone environment variable +ENV TZ=Etc/UTC -FROM alpine AS production -COPY --from=build /app/tenants /app/tenants -ENTRYPOINT ["/app/tenants"] +# Run the binary +ENTRYPOINT ["/tenants"] diff --git a/services/tracing/Dockerfile b/services/tracing/Dockerfile index 817c0e2..98340ef 100644 --- a/services/tracing/Dockerfile +++ b/services/tracing/Dockerfile @@ -1,13 +1,43 @@ +# Build stage FROM golang:1.21-alpine AS builder -WORKDIR /sensorbucket -COPY go.mod . -COPY go.sum . +# Set working directory +WORKDIR /app + +# Install build dependencies +RUN apk add --no-cache git ca-certificates tzdata + +# Copy go mod and sum files +COPY go.mod go.sum ./ + +# Download dependencies RUN go mod download +# Copy the source code COPY . . -RUN CGO_ENABLED=0 go build -ldflags '-extldflags "-static"' -tags timetzdata -o /tracing services/tracing/main.go +# Build the application +ARG TARGETOS=linux +ARG TARGETARCH=amd64 +RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build \ + -ldflags='-w -s -extldflags "-static"' \ + -tags timetzdata \ + -o /tracing \ + services/tracing/main.go + +# Final stage FROM scratch AS production + +WORKDIR / + +# Copy timezone data +COPY --from=builder /usr/share/zoneinfo /usr/share/zoneinfo +# Copy CA certificates +COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ +# Copy the binary from the builder stage COPY --from=builder /tracing /tracing +# Set timezone environment variable +ENV TZ=Etc/UTC + +# Run the binary ENTRYPOINT ["/tracing"]