🚀 CD build.

This commit is contained in:
Daniel Aloni 2023-03-15 16:19:22 +02:00
parent e2d12de97d
commit 9f7c1804b2
2 changed files with 18 additions and 3 deletions

View file

@ -1,6 +1,6 @@
steps: steps:
- name: gcr.io/cloud-builders/docker - name: gcr.io/cloud-builders/docker
args: ['build', '-t', 'gcr.io/$PROJECT_ID/dendrite-monolith:$COMMIT_SHA', '-f', 'Dockerfile', '.'] args: ['build', '--build-arg', 'BUILDPLATFORM=linux/amd64', '-t', 'gcr.io/$PROJECT_ID/dendrite-monolith:$COMMIT_SHA', '-f', 'Dockerfile', '.']
- name: gcr.io/cloud-builders/kubectl - name: gcr.io/cloud-builders/kubectl
args: ['-n', 'dendrite', 'set', 'image', 'deployment/dendrite', 'dendrite=gcr.io/$PROJECT_ID/dendrite-monolith:$COMMIT_SHA'] args: ['-n', 'dendrite', 'set', 'image', 'deployment/dendrite', 'dendrite=gcr.io/$PROJECT_ID/dendrite-monolith:$COMMIT_SHA']
env: env:

View file

@ -4,8 +4,23 @@
FROM --platform=${BUILDPLATFORM} docker.io/golang:1.20-alpine AS base FROM --platform=${BUILDPLATFORM} docker.io/golang:1.20-alpine AS base
RUN apk --update --no-cache add bash build-base curl RUN apk --update --no-cache add bash build-base curl
WORKDIR /build #
COPY . /build # build creates all needed binaries
#
FROM --platform=${BUILDPLATFORM} base AS build
WORKDIR /src
ARG TARGETOS
ARG TARGETARCH
ARG FLAGS
RUN --mount=target=. \
--mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/go/pkg/mod \
USERARCH=`go env GOARCH` \
GOARCH="$TARGETARCH" \
GOOS="linux" \
CGO_ENABLED=$([ "$TARGETARCH" = "$USERARCH" ] && echo "1" || echo "0") \
go build -v -ldflags="${FLAGS}" -trimpath -o /out/ ./cmd/...
# #
# Builds the Dendrite image containing all required binaries # Builds the Dendrite image containing all required binaries