Skip to content

Commit

Permalink
chore(add): Add multiarch image support for chaos-exporter (#76)
Browse files Browse the repository at this point in the history
Signed-off-by: Udit Gaurav <[email protected]>
  • Loading branch information
uditgaurav authored Nov 15, 2020
1 parent 44fa613 commit e11c93a
Show file tree
Hide file tree
Showing 11 changed files with 101 additions and 79 deletions.
18 changes: 17 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,29 @@ services:
- docker
language: go
go:
- 1.13.1
- 1.14.2

addons:
apt:
update: true

before_script:

- set -e
# Configure environment so changes are picked up when the Docker daemon is restarted after upgrading
- echo '{"experimental":true}' | sudo tee /etc/docker/daemon.json
- export DOCKER_CLI_EXPERIMENTAL=enabled
- docker run --rm --privileged docker/binfmt:a7996909642ee92942dcd6cff44b9b95f08dad64
# Upgrade to Docker CE 19.03 for BuildKit support
- curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
- sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
- sudo apt-get update
- sudo apt-get -y -o Dpkg::Options::="--force-confnew" install docker-ce=5:19.03.8~3-0~ubuntu-xenial # pin version for reproducibility
# Show info to simplify debugging and create a builder
- docker info
- docker buildx create --name builder --use
- docker buildx ls
- sudo docker version
# Download kubectl, which is a requirement for using minikube.
- curl -Lo kubectl https://storage.googleapis.com/kubernetes-release/release/v1.13.0/bin/linux/amd64/kubectl && chmod +x kubectl && sudo mv kubectl /usr/local/bin/
# Download minikube.
Expand Down
7 changes: 5 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
FROM ubuntu:16.04

ARG TARGETARCH

RUN apt-get update && apt-get install -y ca-certificates && rm -rf /var/cache/apk/*

COPY ./exporter /
COPY ./exporter-${TARGETARCH} /

EXPOSE 8080

CMD ["/exporter"]
CMD ["/exporter-${TARGETARCH}"]



Expand Down
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,14 @@ go-build:
@echo "------------------"
@echo "--> Build Chaos Exporter"
@echo "------------------"
@go build ./cmd/exporter
@bash build/go-multiarch-build.sh ./cmd/exporter

docker-build:
@echo "------------------"
@echo "--> Build chaos-exporter image"
@echo "------------------"
# Dockerfile available in the repo root
sudo docker build . -f Dockerfile -t $(DOCKER_REPO)/$(DOCKER_IMAGE):$(DOCKER_TAG)
@sudo docker buildx build --file Dockerfile --progress plane --platform linux/arm64,linux/amd64 --no-cache --tag $(DOCKER_REPO)/$(DOCKER_IMAGE):$(DOCKER_TAG) .

.PHONY: test
test:
Expand Down Expand Up @@ -117,4 +117,4 @@ unused-package-check:
@tidy=$$(go mod tidy); \
if [ -n "$${tidy}" ]; then \
echo "go mod tidy checking failed!"; echo "$${tidy}"; echo; \
fi
fi
36 changes: 0 additions & 36 deletions build/gitlab/stages/1-cluster-setup/gcp

This file was deleted.

31 changes: 0 additions & 31 deletions build/gitlab/stages/2-cluster-cleanup/cluster-cleanup

This file was deleted.

27 changes: 27 additions & 0 deletions build/go-multiarch-build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env bash

package=$1
if [[ -z "$package" ]]; then
echo "usage: $0 <package-name>"
exit 1
fi
package_split=(${package//\// })
package_name=${package_split[-1]}

# add the arch for which we want to build the image
platforms=("linux/amd64" "linux/arm64")
for platform in "${platforms[@]}"
do
platform_split=(${platform//\// })
GOOS=${platform_split[0]}
GOARCH=${platform_split[1]}
output_name=exporter-$GOARCH

# The script executes for the argument passed (in package variable)
# here the arg will be "./cmd/exporter" for creating binary
env GOOS=$GOOS GOARCH=$GOARCH go build -o $output_name $package
if [ $? -ne 0 ]; then
echo 'An error has occurred! Aborting the script execution...'
exit 1
fi
done
8 changes: 3 additions & 5 deletions buildscripts/push
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,16 @@ then
sudo docker login -u "${DNAME}" -p "${DPASS}";
# Push image to docker hub
echo "Pushing ${REPONAME}/${IMGNAME}:${IMGTAG} ...";
sudo docker push ${REPONAME}/${IMGNAME}:${IMGTAG} ;
sudo docker buildx build --file Dockerfile --push --progress plane --platform linux/arm64,linux/amd64 --no-cache --tag ${REPONAME}/${IMGNAME}:${IMGTAG} .
if [ ! -z "${TRAVIS_TAG}" ] ;
then
# Push with different tags if tagged as a release
# When github is tagged with a release, then Travis will
# set the release tag in env TRAVIS_TAG
echo "Pushing ${REPONAME}/${IMGNAME}:${TRAVIS_TAG} ...";
sudo docker tag ${IMAGEID} ${REPONAME}/${IMGNAME}:${TRAVIS_TAG}
sudo docker push ${REPONAME}/${IMGNAME}:${TRAVIS_TAG};
sudo docker buildx build --file Dockerfile --push --progress plane --platform linux/arm64,linux/amd64 --no-cache --tag ${REPONAME}/${IMGNAME}:${TRAVIS_TAG} .
echo "Pushing ${REPONAME}/${IMGNAME}:latest ...";
sudo docker tag ${IMAGEID} ${REPONAME}/${IMGNAME}:latest
sudo docker push ${REPONAME}/${IMGNAME}:latest;
sudo docker buildx build --file Dockerfile --push --progress plane --platform linux/arm64,linux/amd64 --no-cache --tag ${REPONAME}/${IMGNAME}:latest .
fi;
else
echo "No docker credentials provided. Skip uploading ${REPONAME}/${IMGNAME}:${IMGTAG} to docker hub";
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ require (
github.com/litmuschaos/chaos-operator v0.0.0-20200502085045-ae0a262d3baa
github.com/onsi/ginkgo v1.12.0
github.com/onsi/gomega v1.9.0
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.6.0
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550 // indirect
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b // indirect
Expand Down
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ github.com/peterbourgon/diskv v2.0.1+incompatible/go.mod h1:uqqh8zWWbv1HBMNONnaR
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
Expand Down
6 changes: 5 additions & 1 deletion tests/bdd/bdd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ var _ = BeforeSuite(func() {
log.Fatalf("Failed to create operator: %v", err)
}
time.Sleep(30 * time.Second)
podDeleteRbac := exec.Command("kubectl", "apply", "-f", "../manifest/pod-delete-rbac.yaml", "-n", "litmus")
if err := podDeleteRbac.Start(); err != nil {
log.Fatalf("Failed to create pod-delete rbac: %v", err)
}
experimentCreate := exec.Command("kubectl", "apply", "-f", "https://hub.litmuschaos.io/api/chaos/master?file=charts/generic/experiments.yaml", "-n", "litmus")
if err := experimentCreate.Start(); err != nil {
log.Fatalf("Failed to create experiment: %v", err)
Expand Down Expand Up @@ -140,7 +144,7 @@ var _ = BeforeSuite(func() {
Applabel: "app=nginx",
AppKind: "deployment",
},
ChaosServiceAccount: "litmus",
ChaosServiceAccount: "pod-delete-sa",
Components: v1alpha1.ComponentParams{
Runner: v1alpha1.RunnerInfo{
Image: "litmuschaos/chaos-runner:ci",
Expand Down
39 changes: 39 additions & 0 deletions tests/manifest/pod-delete-rbac.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: pod-delete-sa
namespace: litmus
labels:
name: pod-delete-sa
app.kubernetes.io/part-of: litmus
---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: pod-delete-sa
namespace: litmus
labels:
name: pod-delete-sa
app.kubernetes.io/part-of: litmus
rules:
- apiGroups: ["","litmuschaos.io","batch","apps"]
resources: ["pods","deployments","pods/log","events","jobs","chaosengines","chaosexperiments","chaosresults"]
verbs: ["create","list","get","patch","update","delete","deletecollection"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: pod-delete-sa
namespace: litmus
labels:
name: pod-delete-sa
app.kubernetes.io/part-of: litmus
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: pod-delete-sa
subjects:
- kind: ServiceAccount
name: pod-delete-sa
namespace: litmus

0 comments on commit e11c93a

Please sign in to comment.