Skip to content

Commit

Permalink
ci: move crossplatform to be handled by go compiler
Browse files Browse the repository at this point in the history
  • Loading branch information
TimVosch committed Jun 25, 2024
1 parent bfd7882 commit 0e9e827
Show file tree
Hide file tree
Showing 8 changed files with 263 additions and 66 deletions.
39 changes: 19 additions & 20 deletions .github/workflows/build-docker-images.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ on:
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
BUILDCACHE_TAG: ghcr.io/sensorbucket/gacache:${{ github.sha }}

jobs:
test:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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' }}
38 changes: 34 additions & 4 deletions services/core/Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
48 changes: 36 additions & 12 deletions services/dashboard/Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]

38 changes: 34 additions & 4 deletions services/fission-rmq-connector/Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
42 changes: 36 additions & 6 deletions services/fission-user-workers/Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
38 changes: 34 additions & 4 deletions services/httpimporter/Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
48 changes: 36 additions & 12 deletions services/tenants/Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]

Loading

0 comments on commit 0e9e827

Please sign in to comment.