Skip to content

Commit 07d5b1e

Browse files
author
Roberto Santalla
authored
Multiarch support (#70)
* docker multiarch support * add cross-build job to push_pr * fix emptyness check * add multiarch dockerfile * comment push for release testing * comment tag check step * fix variable name * add missing dependency * remove --load * changes here and there * build and push at the same time * try to build before pushing * add missing \ * unify Multiarch.dockerfile and Dockerfile * sync goarch variants, hold artifacts for 1 day only * add small help text on dockerfile * cosmetic changes * use tini * move binary to entrypoint * bump minikube * use docker driver * set GOOS and GOARCH explicitly * set DOCKER_BUILDKIT to 1 * set DOCKER_BUILDKIT to 1, harder * ARGs after FROM * specify entrypoint * disable CGO * remove whoami * remove buildkit var * tweak e2e matrix behavior * use 'none' driver for e2e * minor changes * increase max-parallel * chmod while adding * set DOCKER_BUILDKIT in env * move after ADD * pin go version * setup helm with action * back to manual installation method * e2e test in 1.20 * remove stray comments * single quotes * k8s patch version update round * switch back to prod values in release pipeline * curly braces on car * bump version * update base image * manusa/actions-setup-minikube@v2.3.1 * point to non-rc bundle image
1 parent c87090a commit 07d5b1e

10 files changed

Lines changed: 190 additions & 94 deletions

File tree

.github/workflows/e2e.yaml

Lines changed: 35 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -10,43 +10,41 @@ jobs:
1010
e2eTests:
1111
runs-on: ubuntu-18.04
1212
strategy:
13+
max-parallel: 6
1314
matrix:
14-
## we could run priviledgedMode this in serie instead of in //
15-
## PRO less total time, less expensive CONTRA slower to get results
1615
privilegedMode: [ "normal", "unprivileged" ]
17-
k8sVersion: [ "v1.15.12", "v1.16.15", "v1.17.14", "v1.18.12", "v1.19.4" ]
16+
k8sVersion: [ "v1.15.12", "v1.16.15", "v1.17.17", "v1.18.16", "v1.19.8", "v1.20.4" ]
17+
env:
18+
DOCKER_BUILDKIT: '1' # Setting DOCKER_BUILDKIT=1 ensures TARGETOS and TARGETARCH are populated
1819
steps:
19-
- name: Checkout Code
20-
uses: actions/checkout@v2.3.4
21-
- name: Install Go
22-
uses: actions/setup-go@v2
23-
with:
24-
go-version: '^1.14.4'
25-
- name: Setup Helm and Socat
26-
run: |
27-
curl https://get.helm.sh/helm-v2.17.0-linux-amd64.tar.gz --output helm.tar.gz
28-
tar -zxvf helm.tar.gz
29-
sudo mv linux-amd64/helm /usr/local/bin/helm
30-
sudo mv linux-amd64/tiller /usr/local/bin/tiller
31-
32-
sudo apt-get update -y && sudo apt-get install -y socat
33-
- name: Setup Minikube
34-
uses: manusa/actions-setup-minikube@v2.0.1
35-
with:
36-
minikube version: 'v1.15.1'
37-
kubernetes version: '${{ matrix.k8sVersion }}'
38-
#driver: docker
39-
- name: Compile and Build Image
40-
run: |
41-
make compile
42-
eval $(minikube docker-env)
43-
docker build -t test_image_${{ matrix.privilegedMode }}:test --build-arg 'MODE=${{ matrix.privilegedMode }}' .
44-
docker run --rm -i test_image_${{ matrix.privilegedMode }}:test whoami
45-
- name: Interact with the cluster
46-
run: |
47-
if [ "${{ matrix.privilegedMode }}" = "unprivileged" ]; then
48-
UNPRIVILEGED=true
49-
else
50-
UNPRIVILEGED=false
51-
fi
52-
go run e2e/cmd/e2e.go --verbose --cluster_name=e2e --nr_license_key="fakeLicense" --rbac=true --integration_image_tag=test --integration_image_repository=test_image_${{ matrix.privilegedMode }} --k8s_version=${{ matrix.k8sVersion }} --unprivileged=$UNPRIVILEGED
20+
- uses: actions/checkout@v2
21+
- uses: actions/setup-go@v2
22+
with:
23+
go-version: '1.16'
24+
- name: Setup Helm and Socat
25+
# 2.17.0 is the last version of the 2.x branch, which we require for the e2e scripts
26+
run: |
27+
sudo apt-get update -y && sudo apt-get install -y socat
28+
curl -sSL https://get.helm.sh/helm-v2.17.0-linux-amd64.tar.gz --output helm.tar.gz
29+
tar -zxvf helm.tar.gz
30+
sudo mv linux-amd64/helm /usr/local/bin/helm
31+
sudo mv linux-amd64/tiller /usr/local/bin/tiller
32+
- name: Setup Minikube
33+
uses: manusa/actions-setup-minikube@v2.3.1
34+
with:
35+
minikube version: v1.19.0
36+
kubernetes version: ${{ matrix.k8sVersion }}
37+
driver: none # required for nri-kubernetes, as metrics gathered for the host are tested as well
38+
- name: Compile and Build Image
39+
run: |
40+
GOOS=linux GOARCH=amd64 make compile # Set GOOS and GOARCH explicitly since Dockerfile expects them in the binary name
41+
docker build -t test_image_${{ matrix.privilegedMode }}:test --build-arg 'MODE=${{ matrix.privilegedMode }}' .
42+
- name: Interact with the cluster
43+
continue-on-error: ${{ contains(matrix.k8sVersion, '1.20') }} # experimental support for 1.20.x
44+
run: |
45+
if [ "${{ matrix.privilegedMode }}" = "unprivileged" ]; then
46+
UNPRIVILEGED=true
47+
else
48+
UNPRIVILEGED=false
49+
fi
50+
go run e2e/cmd/e2e.go --verbose --cluster_name=e2e --nr_license_key="fakeLicense" --rbac=true --integration_image_tag=test --integration_image_repository=test_image_${{ matrix.privilegedMode }} --k8s_version=${{ matrix.k8sVersion }} --unprivileged=$UNPRIVILEGED

.github/workflows/push_pr.yaml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: lint and test code
2+
on:
3+
push:
4+
branches:
5+
- main
6+
pull_request:
7+
jobs:
8+
build:
9+
name: Build integration for
10+
runs-on: ubuntu-latest
11+
strategy:
12+
matrix:
13+
goos: [ linux ]
14+
goarch: [ amd64, arm64, arm ]
15+
steps:
16+
- uses: actions/checkout@v2
17+
- uses: actions/setup-go@v2
18+
with:
19+
go-version: '1.16'
20+
- name: Build integration
21+
env:
22+
GOOS: ${{ matrix.goos }}
23+
GOARCH: ${{ matrix.goarch }}
24+
run: |
25+
make compile
26+
test:
27+
name: Unit tests
28+
needs: [ build ]
29+
runs-on: ubuntu-latest
30+
steps:
31+
- uses: actions/checkout@v2
32+
- uses: actions/setup-go@v2
33+
with:
34+
go-version: '1.16'
35+
- name: Run unit tests
36+
run: make test
37+
lint:
38+
name: Linter
39+
runs-on: ubuntu-latest
40+
steps:
41+
- uses: actions/checkout@v2
42+
- name: golangci-lint
43+
uses: golangci/golangci-lint-action@v2
44+
with:
45+
version: v1.29

.github/workflows/release.yml

Lines changed: 71 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,62 +5,114 @@ on:
55
types: [prereleased, released]
66

77
jobs:
8+
build:
9+
name: Build integration for
10+
runs-on: ubuntu-latest
11+
strategy:
12+
matrix:
13+
goos: [ linux ]
14+
goarch: [ amd64, arm64, arm ]
15+
steps:
16+
- uses: actions/checkout@v2
17+
- uses: actions/setup-go@v2
18+
with:
19+
go-version: '1.16'
20+
- name: Build integration
21+
env:
22+
GOOS: ${{ matrix.goos }}
23+
GOARCH: ${{ matrix.goarch }}
24+
run: |
25+
make compile
26+
- name: Upload artifact for docker build step
27+
uses: actions/upload-artifact@v2
28+
with:
29+
retention-days: 1
30+
name: nri-kubernetes-${{ matrix.goos }}-${{ matrix.goarch }}
31+
path: bin/nri-kubernetes-${{ matrix.goos }}-${{ matrix.goarch }}
32+
833
release:
934
name: Release docker images and config
35+
needs: [ build ]
1036
runs-on: ubuntu-latest
1137
env:
1238
DOCKER_IMAGE_NAME: newrelic/infrastructure-k8s
39+
DOCKER_PLATFORMS: "linux/amd64,linux/arm64,linux/arm" # Must be consistent with the matrix from the job above
1340
S3_PATH: s3://nr-downloads-main/infrastructure_agent
1441
steps:
1542
- name: Generate docker image version from git tag
1643
run: |
1744
echo "${{ github.event.release.tag_name }}" | grep -E '^v[0-9.]*[0-9]$'
1845
DOCKER_IMAGE_TAG=$(echo "${{ github.event.release.tag_name }}" | sed 's/^v//')
19-
echo "$DOCKER_IMAGE_TAG" | grep -E '^[0-9.]*[0-9]$'
2046
echo "DOCKER_IMAGE_TAG=$DOCKER_IMAGE_TAG" >> $GITHUB_ENV
2147
2248
- if: ${{ github.event.release.prerelease }}
2349
run: |
24-
echo "DOCKER_IMAGE_TAG=$DOCKER_IMAGE_TAG-pre" >> $GITHUB_ENV
50+
echo "DOCKER_IMAGE_TAG=${DOCKER_IMAGE_TAG}-pre" >> $GITHUB_ENV
2551
echo "S3_PATH=$S3_PATH/test" >> $GITHUB_ENV
2652
2753
- uses: actions/checkout@v2
2854

29-
# -pre suffix is stripped from safety checks. This will not be necessary when we automate the yaml generation.
55+
# -pre suffix is stripped from yaml consistency check
3056
- name: Check consistency of deployment yamls
3157
run: |
3258
grep -e "$DOCKER_IMAGE_NAME:${DOCKER_IMAGE_TAG/-pre}" deploy/newrelic-infra.yaml
3359
grep -e "$DOCKER_IMAGE_NAME:${DOCKER_IMAGE_TAG/-pre}" deploy/newrelic-infra-unprivileged.yaml
3460
35-
- name: Build docker images
36-
run: |
37-
make compile
38-
docker build -t $DOCKER_IMAGE_NAME:$DOCKER_IMAGE_TAG .
39-
docker build -t $DOCKER_IMAGE_NAME:$DOCKER_IMAGE_TAG-unprivileged --build-arg 'MODE=unprivileged' .
61+
- name: Set up QEMU
62+
uses: docker/setup-qemu-action@v1
63+
- name: Set up Docker Buildx
64+
uses: docker/setup-buildx-action@v1
65+
66+
- name: Download all artifacts from build job
67+
uses: actions/download-artifact@v2
68+
with:
69+
path: bin
70+
4071
- uses: docker/login-action@v1
4172
with:
4273
username: ${{ secrets.FSI_DOCKERHUB_USERNAME }}
4374
password: ${{ secrets.FSI_DOCKERHUB_TOKEN }}
44-
- name: Upload docker images
75+
76+
- name: Build docker images
77+
run: |
78+
docker buildx build --platform=$DOCKER_PLATFORMS \
79+
-t $DOCKER_IMAGE_NAME:$DOCKER_IMAGE_TAG \
80+
.
81+
docker buildx build --platform=$DOCKER_PLATFORMS \
82+
--build-arg 'MODE=unprivileged' \
83+
-t $DOCKER_IMAGE_NAME:$DOCKER_IMAGE_TAG-unprivileged \
84+
.
85+
- name: Push versioned images
4586
run: |
46-
docker push $DOCKER_IMAGE_NAME:$DOCKER_IMAGE_TAG
47-
docker push $DOCKER_IMAGE_NAME:$DOCKER_IMAGE_TAG-unprivileged
48-
- name: Tag and push docker :latest images
87+
docker buildx build --push --platform=$DOCKER_PLATFORMS \
88+
-t $DOCKER_IMAGE_NAME:$DOCKER_IMAGE_TAG \
89+
.
90+
docker buildx build --push --platform=$DOCKER_PLATFORMS \
91+
--build-arg 'MODE=unprivileged' \
92+
-t $DOCKER_IMAGE_NAME:$DOCKER_IMAGE_TAG-unprivileged \
93+
.
94+
- name: Push :latest images
4995
if: ${{ ! github.event.release.prerelease }}
5096
run: |
51-
docker tag $DOCKER_IMAGE_NAME:$DOCKER_IMAGE_TAG $DOCKER_IMAGE_NAME:latest
52-
docker tag $DOCKER_IMAGE_NAME:$DOCKER_IMAGE_TAG-unprivileged $DOCKER_IMAGE_NAME:latest-unprivileged
53-
docker push $DOCKER_IMAGE_NAME:latest
54-
docker push $DOCKER_IMAGE_NAME:latest-unprivileged
97+
docker buildx build --push --platform=$DOCKER_PLATFORMS \
98+
-t $DOCKER_IMAGE_NAME:latest \
99+
.
100+
docker buildx build --push --platform=$DOCKER_PLATFORMS \
101+
--build-arg 'MODE=unprivileged' \
102+
-t $DOCKER_IMAGE_NAME:latest-unprivileged \
103+
.
55104
56105
- uses: aws-actions/configure-aws-credentials@v1
57106
with:
58107
aws-access-key-id: ${{ secrets.COREINT_AWS_ACCESS_KEY_ID }}
59108
aws-secret-access-key: ${{ secrets.COREINT_AWS_SECRET_ACCESS_KEY }}
60109
aws-region: us-east-1
61-
- name: Upload configuration files to https://download.newrelic.com
110+
- name: Upload versioned manifests to S3
111+
run: |
112+
aws s3 cp deploy/newrelic-infra.yaml $S3_PATH/integrations/kubernetes/newrelic-infrastructure-k8s-${DOCKER_IMAGE_TAG}.yaml
113+
aws s3 cp deploy/newrelic-infra-unprivileged.yaml $S3_PATH/integrations/kubernetes/newrelic-infrastructure-k8s-unprivileged-${DOCKER_IMAGE_TAG}.yaml
114+
- name: Upload latest manifests to S3
115+
if: ${{ ! github.event.release.prerelease }}
62116
run: |
63-
aws s3 cp deploy/newrelic-infra.yaml $S3_PATH/integrations/kubernetes/newrelic-infrastructure-k8s-$DOCKER_IMAGE_TAG.yaml
64117
aws s3 cp deploy/newrelic-infra.yaml $S3_PATH/integrations/kubernetes/newrelic-infrastructure-k8s-latest.yaml
65-
aws s3 cp deploy/newrelic-infra-unprivileged.yaml $S3_PATH/integrations/kubernetes/newrelic-infrastructure-k8s-unprivileged-$DOCKER_IMAGE_TAG.yaml
66118
aws s3 cp deploy/newrelic-infra-unprivileged.yaml $S3_PATH/integrations/kubernetes/newrelic-infrastructure-k8s-unprivileged-latest.yaml

.github/workflows/test.yaml

Lines changed: 0 additions & 29 deletions
This file was deleted.

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
88
## Unreleased
99

1010
---
11+
12+
## 2.4.0
13+
14+
### Added
15+
16+
- Support for multiarch docker images
17+
1118
## 2.3.1
1219

1320
### Fixed

Dockerfile

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,24 @@
11
ARG IMAGE_NAME=newrelic/infrastructure-bundle
2-
ARG IMAGE_TAG=2.2.3
2+
ARG IMAGE_TAG=2.4.1
3+
34
ARG MODE=normal
45

56
FROM $IMAGE_NAME:$IMAGE_TAG AS base
7+
8+
# Set by docker automatically
9+
# If building with `docker build`, make sure to set GOOS/GOARCH explicitly when calling make:
10+
# `make compile GOOS=something GOARCH=something`
11+
# Otherwise the makefile will not append them to the binary name and docker build wil fail.
12+
ARG TARGETOS
13+
ARG TARGETARCH
14+
615
# ensure there is no default integration enabled
716
RUN rm -rf /etc/newrelic-infra/integrations.d/*
817
ADD nri-kubernetes-definition.yml /var/db/newrelic-infra/newrelic-integrations/
9-
ADD bin/nri-kubernetes /var/db/newrelic-infra/newrelic-integrations/bin/
18+
ADD --chmod=755 bin/nri-kubernetes-${TARGETOS}-${TARGETARCH} /var/db/newrelic-infra/newrelic-integrations/bin/
19+
RUN mv /var/db/newrelic-infra/newrelic-integrations/bin/nri-kubernetes-${TARGETOS}-${TARGETARCH} \
20+
/var/db/newrelic-infra/newrelic-integrations/bin/nri-kubernetes
21+
1022
# Warning: First, Edit sample file to suit your needs and rename it to
1123
# `nri-kubernetes-config.yml`
1224
ADD nri-kubernetes-config.yml.sample /var/db/newrelic-infra/integrations.d/nri-kubernetes-config.yml
@@ -15,13 +27,11 @@ FROM base AS branch-normal
1527
USER root
1628

1729
FROM base AS branch-unprivileged
18-
1930
RUN addgroup -g 2000 nri-agent && adduser -D -u 1000 -G nri-agent nri-agent
2031
USER nri-agent
2132

2233
ENV NRIA_OVERRIDE_HOST_ROOT ""
2334
ENV NRIA_IS_SECURE_FORWARD_ONLY true
2435

2536
FROM branch-${MODE}
26-
ENTRYPOINT ["/sbin/tini", "--"]
27-
CMD ["/usr/bin/newrelic-infra"]
37+
ENTRYPOINT ["/sbin/tini", "--", "/usr/bin/newrelic-infra"]

Makefile

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,19 @@ TOOLS_DIR := $(BIN_DIR)/dev-tools
55
BINARY_NAME = nri-kubernetes
66
E2E_BINARY_NAME := $(BINARY_NAME)-e2e
77

8+
# GOOS and GOARCH will likely come from env
9+
GOOS ?=
10+
GOARCH ?=
11+
CGO_ENABLED ?= 0
12+
13+
ifneq ($(strip $(GOOS)), )
14+
BINARY_NAME := $(BINARY_NAME)-$(GOOS)
15+
endif
16+
17+
ifneq ($(strip $(GOARCH)), )
18+
BINARY_NAME := $(BINARY_NAME)-$(GOARCH)
19+
endif
20+
821
GOLANGCILINT_VERSION = 1.36.0
922

1023
.PHONY: all
@@ -38,7 +51,7 @@ lint-all: $(TOOLS_DIR)/golangci-lint
3851
.PHONY: compile
3952
compile:
4053
@echo "[compile] Building $(BINARY_NAME)"
41-
@go build -o $(BIN_DIR)/$(BINARY_NAME) ./src
54+
CGO_ENABLED=$(CGO_ENABLED) go build -o $(BIN_DIR)/$(BINARY_NAME) ./src
4255

4356
.PHONY: compile-dev
4457
compile-dev:

deploy/newrelic-infra-unprivileged.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ spec:
8383
serviceAccountName: newrelic
8484
containers:
8585
- name: newrelic-infra
86-
image: newrelic/infrastructure-k8s:2.3.1-unprivileged
86+
image: newrelic/infrastructure-k8s:2.4.0-unprivileged
8787
resources:
8888
limits:
8989
memory: 150M

deploy/newrelic-infra.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ spec:
8585
dnsPolicy: ClusterFirstWithHostNet
8686
containers:
8787
- name: newrelic-infra
88-
image: newrelic/infrastructure-k8s:2.3.1
88+
image: newrelic/infrastructure-k8s:2.4.0
8989
securityContext:
9090
privileged: true
9191
resources:

0 commit comments

Comments
 (0)