-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from fedepaol/buildinci
Build and push the image from CI
- Loading branch information
Showing
4 changed files
with
165 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
name: Publish | ||
on: | ||
push: | ||
branches: | ||
- "main" | ||
- v* | ||
tags: | ||
- v* | ||
|
||
jobs: | ||
unit-tests: | ||
runs-on: ubuntu-22.04 | ||
steps: | ||
- name: Cancel Previous Runs | ||
uses: styfle/[email protected] | ||
with: | ||
access_token: ${{ github.token }} | ||
|
||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
|
||
- uses: actions/setup-go@v4 | ||
with: | ||
go-version-file: "go.mod" | ||
cache: true | ||
|
||
- uses: actions/setup-go@v4 | ||
with: | ||
go-version-file: "go.mod" | ||
cache: true | ||
|
||
- name: Unit Tests | ||
run: | | ||
make test | ||
- name: Lint | ||
run: | | ||
ENV=host make lint | ||
make bumplicense | ||
go mod tidy | ||
pushd e2etests | ||
go mod tidy | ||
popd | ||
make manifests | ||
make checkuncommitted | ||
publish-images: | ||
runs-on: ubuntu-22.04 | ||
needs: [unit-tests] | ||
permissions: | ||
contents: read | ||
id-token: write # needed for signing the images with GitHub OIDC Token | ||
steps: | ||
- name: Set up QEMU | ||
uses: docker/setup-qemu-action@v2 | ||
|
||
- name: Install Cosign | ||
uses: sigstore/cosign-installer@main | ||
with: | ||
cosign-release: "v1.13.1" | ||
|
||
- name: Code checkout | ||
uses: actions/checkout@v3 | ||
|
||
- name: Setup docker buildx | ||
uses: docker/setup-buildx-action@v2 | ||
|
||
- name: Log into Quay | ||
uses: docker/login-action@v2 | ||
with: | ||
registry: quay.io | ||
username: ${{ secrets.QUAY_USER }} | ||
password: ${{ secrets.QUAY_PASSWORD }} | ||
|
||
- name: Docker meta | ||
id: meta | ||
uses: docker/metadata-action@v4 | ||
with: | ||
images: | | ||
quay.io/metallb/frr-k8s | ||
# generate Docker tags based on the following events/attributes | ||
tags: | | ||
type=ref,event=branch | ||
type=semver,pattern={{raw}} | ||
labels: | | ||
org.opencontainers.image.title=frr-k8s | ||
org.opencontainers.image.description=frr-k8s, a cloud native wrapper of some frr features | ||
- name: Build and push | ||
uses: docker/build-push-action@v4 | ||
id: build-and-push | ||
with: | ||
context: . | ||
tags: ${{ steps.meta.outputs.tags }} | ||
labels: ${{ steps.meta.outputs.labels }} | ||
file: Dockerfile | ||
platforms: linux/amd64,linux/arm64,linux/s390x,linux/ppc64le,linux/arm/v7 | ||
cache-from: type=gha | ||
cache-to: type=gha,mode=max | ||
push: true | ||
build-args: | | ||
GIT_BRANCH: ${{ github.ref_name }} | ||
GIT_COMMIT: ${{ github.sha }} | ||
- name: Cosign sign tags | ||
run: cosign sign ${TAGS} | ||
env: | ||
TAGS: ${{ steps.meta.outputs.tags }}@${{ steps.build-and-push.outputs.digest }} | ||
COSIGN_EXPERIMENTAL: 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,60 @@ | ||
# Build the frr-k8s binary | ||
FROM golang:1.19 as builder | ||
ARG TARGETOS | ||
ARG TARGETARCH | ||
# syntax=docker/dockerfile:1.2 | ||
|
||
FROM --platform=$BUILDPLATFORM docker.io/golang:1.19.5 AS builder | ||
ARG GIT_COMMIT=dev | ||
ARG GIT_BRANCH=dev | ||
WORKDIR $GOPATH/frr-k8s | ||
|
||
WORKDIR /workspace | ||
# Copy the Go Modules manifests | ||
COPY go.mod go.mod | ||
COPY go.sum go.sum | ||
# cache deps before building and copying source so that we don't need to re-download as much | ||
# and so that source changes don't invalidate our downloaded layer | ||
# Cache the downloads | ||
COPY go.mod go.sum ./ | ||
RUN go mod download | ||
|
||
# Copy the go source | ||
COPY cmd/main.go cmd/main.go | ||
COPY api/ api/ | ||
COPY internal/ internal/ | ||
COPY frr-tools/metrics ./frr-tools/metrics/ | ||
|
||
# Build | ||
# the GOARCH has not a default value to allow the binary be built according to the host where the command | ||
# was called. For example, if we call make docker-build in a local env which has the Apple Silicon M1 SO | ||
# the docker BUILDPLATFORM arg will be linux/arm64 when for Apple x86 it will be linux/amd64. Therefore, | ||
# by leaving it empty we can ensure that the container and binary shipped on it will have the same platform. | ||
RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o frr-k8s cmd/main.go | ||
RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o /build/frr-metrics frr-tools/metrics/exporter.go | ||
|
||
FROM alpine:latest | ||
WORKDIR / | ||
COPY --from=builder /workspace/frr-k8s . | ||
ARG TARGETARCH | ||
ARG TARGETOS | ||
ARG TARGETPLATFORM | ||
|
||
# have to manually convert as building the different arms can cause issues | ||
# Extract variant | ||
RUN case ${TARGETPLATFORM} in \ | ||
"linux/arm/v6") export VARIANT="6" ;; \ | ||
"linux/arm/v7") export VARIANT="7" ;; \ | ||
*) export VARIANT="" ;; \ | ||
esac | ||
|
||
# Cache builds directory for faster rebuild | ||
RUN --mount=type=cache,target=/root/.cache/go-build \ | ||
--mount=type=cache,target=/go/pkg \ | ||
# build frr metrics | ||
CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH GOARM=$VARIANT \ | ||
go build -v -o /build/frr-metrics \ | ||
-ldflags "-X 'frr-k8s/internal/version.gitCommit=${GIT_COMMIT}' -X 'frr-k8s/metallb/internal/version.gitBranch=${GIT_BRANCH}'" \ | ||
frr-tools/metrics/exporter.go \ | ||
&& \ | ||
CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH GOARM=$VARIANT \ | ||
go build -v -o /build/frr-k8s \ | ||
-ldflags "-X 'frr-k8s/internal/version.gitCommit=${GIT_COMMIT}' -X 'frr-k8s/internal/version.gitBranch=${GIT_BRANCH}'" \ | ||
cmd/main.go | ||
|
||
FROM docker.io/alpine:latest | ||
|
||
|
||
COPY --from=builder /build/frr-k8s /frr-k8s | ||
COPY --from=builder /build/frr-metrics /frr-metrics | ||
COPY frr-tools/reloader/frr-reloader.sh /frr-reloader.sh | ||
COPY LICENSE / | ||
|
||
LABEL org.opencontainers.image.authors="metallb" \ | ||
org.opencontainers.image.url="https://github.com/metallb/frr-k8s" \ | ||
org.opencontainers.image.source="https://github.com/metallb/frr-k8s" \ | ||
org.opencontainers.image.vendor="metallb" \ | ||
org.opencontainers.image.licenses="Apache-2.0" \ | ||
org.opencontainers.image.description="FRR-K8s" \ | ||
org.opencontainers.image.title="frr-k8s" \ | ||
org.opencontainers.image.base.name="docker.io/alpine:latest" | ||
|
||
ENTRYPOINT ["/frr-k8s"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters