diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f43a61840..50161ef2d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -24,6 +24,13 @@ jobs: - name: Check out code uses: actions/checkout@v2 + - name: Set up QEMU + uses: docker/setup-qemu-action@v1 + + - name: Set up Docker Buildx + id: buildx + uses: docker/setup-buildx-action@v1 + - name: Check licenses env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} @@ -32,8 +39,66 @@ jobs: - name: Run verification run: make check - - name: Build Docker image - run: make docker + - name: Get current timestamp + id: timestamp + run: echo "::set-output name=timestamp::$(date -u +'%Y-%m-%dT%H:%M:%SZ')" + + - name: Build APIClarity + uses: docker/build-push-action@v2 + with: + context: . + platforms: linux/amd64,linux/arm64 + tags: ghcr.io/apiclarity/apiclarity:${{ github.sha }} + file: Dockerfile + cache-from: type=local,src=/tmp/.buildx-cache + cache-to: type=local,dest=/tmp/.buildx-cache + build-args: | + VERSION=${{ github.sha }} + BUILD_TIMESTAMP=${{ steps.timestamp.outputs.timestamp }} + COMMIT_HASH=${{ github.sha }} + + - name: Build Kong plugin + uses: docker/build-push-action@v2 + with: + context: plugins + platforms: linux/amd64,linux/arm64 + tags: ghcr.io/apiclarity/kong-plugin:${{ github.sha }} + file: plugins/Dockerfile.kong + cache-from: type=local,src=/tmp/.buildx-cache + cache-to: type=local,dest=/tmp/.buildx-cache + + - name: Fix Tyk Plugin API dep + id: tyk-dep + run: | + cd plugins/gateway/tyk/v3.2.2 + go mod edit -replace github.com/apiclarity/apiclarity/plugins/api@v0.0.0=./../api + go mod edit -replace github.com/apiclarity/apiclarity/plugins/common@v0.0.0=./../common + + - name: Build Tyk plugin + uses: docker/build-push-action@v2 + with: + context: plugins + platforms: linux/amd64 # tykio/tyk-plugin-compiler does not currently support other architectures + tags: ghcr.io/apiclarity/tyk-plugin-v3.2.2:${{ github.sha }} + file: plugins/Dockerfile.tyk.v3.2.2 + cache-from: type=local,src=/tmp/.buildx-cache + cache-to: type=local,dest=/tmp/.buildx-cache + + - name: Undo Tyk Plugin API dep change + id: undo-tyk-dep + run: git checkout -- plugins/gateway/tyk/v3.2.2/go.mod + + - name: Build passive taper + uses: docker/build-push-action@v2 + with: + context: plugins + platforms: linux/amd64,linux/arm64 + tags: ghcr.io/apiclarity/passive-taper:${{ github.sha }} + file: plugins/Dockerfile.taper + cache-from: type=local,src=/tmp/.buildx-cache + cache-to: type=local,dest=/tmp/.buildx-cache + build-args: | + VERSION=${{ github.sha }} lint_chart: name: Lint Helm Chart diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index ca3f73203..bc007ddeb 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -14,6 +14,9 @@ jobs: with: submodules: true + - name: Set up QEMU + uses: docker/setup-qemu-action@v1 + - name: Set up Docker Buildx uses: docker/setup-buildx-action@v1 @@ -40,6 +43,7 @@ jobs: uses: docker/build-push-action@v2 with: context: . + platforms: linux/amd64,linux/arm64 tags: ghcr.io/apiclarity/apiclarity:latest file: Dockerfile push: true @@ -54,6 +58,7 @@ jobs: uses: docker/build-push-action@v2 with: context: plugins + platforms: linux/amd64,linux/arm64 tags: ghcr.io/apiclarity/kong-plugin:latest file: plugins/Dockerfile.kong push: true @@ -71,6 +76,7 @@ jobs: uses: docker/build-push-action@v2 with: context: plugins + platforms: linux/amd64 # tykio/tyk-plugin-compiler does not currently support other architectures tags: ghcr.io/apiclarity/tyk-plugin-v3.2.2:latest file: plugins/Dockerfile.tyk.v3.2.2 push: true @@ -81,6 +87,7 @@ jobs: uses: docker/build-push-action@v2 with: context: plugins + platforms: linux/amd64,linux/arm64 tags: ghcr.io/apiclarity/passive-taper:latest file: plugins/Dockerfile.taper push: true diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index b979ca03e..8fb747037 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -81,6 +81,9 @@ jobs: git tag --annotate --message "Tag for release $tag" "$tag" git push origin "refs/tags/$tag" + - name: Set up QEMU + uses: docker/setup-qemu-action@v1 + - name: Set up Docker Buildx uses: docker/setup-buildx-action@v1 @@ -107,6 +110,7 @@ jobs: uses: docker/build-push-action@v2 with: context: . + platforms: linux/amd64,linux/arm64 tags: ghcr.io/apiclarity/apiclarity:${{ github.event.inputs.version }} file: Dockerfile push: true @@ -121,6 +125,7 @@ jobs: uses: docker/build-push-action@v2 with: context: plugins + platforms: linux/amd64,linux/arm64 tags: ghcr.io/apiclarity/kong-plugin:${{ github.event.inputs.version }} file: plugins/Dockerfile.kong push: true @@ -138,6 +143,7 @@ jobs: uses: docker/build-push-action@v2 with: context: plugins + platforms: linux/amd64 # tykio/tyk-plugin-compiler does not currently support other architectures tags: ghcr.io/apiclarity/tyk-plugin-v3.2.2:${{ github.event.inputs.version }} file: plugins/Dockerfile.tyk.v3.2.2 push: true @@ -152,6 +158,7 @@ jobs: uses: docker/build-push-action@v2 with: context: plugins + platforms: linux/amd64,linux/arm64 tags: ghcr.io/apiclarity/passive-taper:${{ github.event.inputs.version }} file: plugins/Dockerfile.taper push: true diff --git a/Dockerfile b/Dockerfile index 4dd264646..484760aee 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,9 +7,9 @@ RUN npm i RUN npm run build -FROM golang:1.16.6-alpine AS builder +FROM --platform=$BUILDPLATFORM golang:1.16.6-alpine AS builder -RUN apk add --update --no-cache gcc g++ +RUN apk add --no-cache build-base WORKDIR /build COPY api ./api @@ -25,7 +25,8 @@ ARG COMMIT_HASH # Copy and build backend code COPY backend . -RUN go build -ldflags="-s -w \ +ARG TARGETOS TARGETARCH +RUN GOOS=$TARGETOS GOARCH=$TARGETARCH go build -ldflags="-s -w \ -X 'github.com/apiclarity/apiclarity/backend/pkg/version.Version=${VERSION}' \ -X 'github.com/apiclarity/apiclarity/backend/pkg/version.CommitHash=${COMMIT_HASH}' \ -X 'github.com/apiclarity/apiclarity/backend/pkg/version.BuildTimestamp=${BUILD_TIMESTAMP}'" -o backend ./cmd/backend/main.go diff --git a/plugins/Dockerfile.kong b/plugins/Dockerfile.kong index 957a16978..4c7c7b3e0 100644 --- a/plugins/Dockerfile.kong +++ b/plugins/Dockerfile.kong @@ -1,8 +1,8 @@ -FROM golang:1.16.6-alpine AS builder +FROM --platform=$BUILDPLATFORM golang:1.16.6-alpine AS builder ## Note: this Dockerfile will only be built from the plugins context -RUN apk add --update --no-cache gcc g++ +RUN apk add --no-cache build-base WORKDIR /plugins COPY api ./api @@ -22,7 +22,8 @@ RUN go mod download COPY gateway/kong . # Build the plugin. -RUN go build -o bin/kong-plugin plugin.go +ARG TARGETOS TARGETARCH +RUN GOOS=$TARGETOS GOARCH=$TARGETARCH go build -o bin/kong-plugin plugin.go FROM busybox COPY --from=builder ["/plugins/gateway/kong/bin/kong-plugin", "/kong-plugin"] diff --git a/plugins/Dockerfile.taper b/plugins/Dockerfile.taper index fd7137c94..329bfa7cd 100644 --- a/plugins/Dockerfile.taper +++ b/plugins/Dockerfile.taper @@ -1,9 +1,10 @@ -FROM golang:1.16.6-alpine AS builder +FROM --platform=$BUILDPLATFORM golang:1.16.6-alpine AS builder # Set necessary environment variables needed for our image. -ENV CGO_ENABLED=1 GOOS=linux GOARCH=amd64 +ARG TARGETOS TARGETARCH +ENV CGO_ENABLED=1 GOOS=$TARGETOS GOARCH=$TARGETARCH -RUN apk add libpcap-dev gcc g++ make bash +RUN apk add --no-cache build-base binutils-gold libpcap-dev WORKDIR /plugins @@ -27,7 +28,7 @@ RUN go build -buildmode=plugin -o ../http.so . FROM alpine:3.14 -RUN apk add bash libpcap-dev tcpdump +RUN apk add --no-cache bash libpcap tcpdump WORKDIR /app # Copy binary and config files from /build to root folder of scratch container.