Skip to content
This repository was archived by the owner on Jul 28, 2023. It is now read-only.

Commit 1621bc3

Browse files
author
CameronMcWilliam
authored
Multi architecture support for init-controller image (#68)
* support multiple docker arch image * have to use buildx * trying travis * changed default repo for deploy * changed repo * edited out releases on travis branch * commented out tests * change to use TRAVIS TAG * removed tests * removed test script * install qemu * changed script * check contnets of package * list contents * list package * changed makefile * reverted back to allow merge into appsody * removed return at the end of test file * removed duplicate line at start of script * changes from feeedback * fixed declare
1 parent 3039d55 commit 1621bc3

6 files changed

Lines changed: 30 additions & 10 deletions

File tree

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/controller
22
/build
33
/package
4-
.vscode/
4+
.vscode/
5+
.DS_Store

.travis.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@ go_import_path: github.com/appsody/controller
1212
services:
1313
- docker
1414

15+
#Install later docker version
16+
before_install:
17+
- curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
18+
- sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
19+
- sudo apt-get update
20+
- sudo apt-get -y -o Dpkg::Options::="--force-confnew" install docker-ce
21+
1522
# skip because dependencies are baked in vendor dir
1623
install: true
1724

@@ -35,7 +42,7 @@ deploy:
3542
repo: appsody/controller
3643
- provider: script
3744
skip_cleanup: true
38-
script: bash ./build.sh
45+
script: ./build.sh
3946
on:
4047
tags: true
4148
repo: appsody/controller

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
FROM busybox
2-
3-
COPY ./package/appsody-controller /appsody-controller
2+
ARG TARGETPLATFORM
3+
COPY ./package/appsody-controller-$TARGETPLATFORM /appsody-controller
44
RUN chmod +x /appsody-controller
55
WORKDIR /
66
CMD ["cp","/appsody-controller","/.appsody/appsody-controller"]

Makefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,13 @@ clean: ## Removes existing build artifacts in order to get a fresh build
5151

5252
.PHONY: build
5353
build: ## Build binary for linux stores it in the build/ dir
54-
GOOS=linux CGO_ENABLED=0 GOARCH=amd64 go build -o $(BUILD_PATH)/$(COMMAND) -ldflags "-X main.VERSION=$(VERSION)"
54+
chmod u+r+x go_build.sh
55+
./go_build.sh $(VERSION)
5556

5657
.PHONY: package
5758
package: build ## Build the linux binary and stores it in package/ dir
5859
mkdir -p $(PACKAGE_PATH)
59-
cp -p $(BUILD_PATH)/$(COMMAND) $(PACKAGE_PATH)/
60+
cp -ap $(BUILD_PATH)/. $(PACKAGE_PATH)/
6061

6162
# Auto documented help from http://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
6263
.PHONY: help

build.sh

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
#!/bin/bash
2-
3-
42
set -e
53
echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
6-
docker build -t $DOCKER_ORG/init-controller:$TRAVIS_TAG -t $DOCKER_ORG/init-controller:latest .
7-
docker push $DOCKER_ORG/init-controller
4+
# enables experimental daemon for docker buildx: https://docs.docker.com/buildx/working-with-buildx/
5+
# minimum docker version required for buildx is v19.03
6+
export DOCKER_CLI_EXPERIMENTAL=enabled
7+
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
8+
docker buildx create --name mybuilder
9+
docker buildx use mybuilder
10+
docker buildx build -t $DOCKER_ORG/init-controller:$TRAVIS_TAG -t $DOCKER_ORG/init-controller:latest --platform=linux/amd64,linux/ppc64le,linux/s390x . --push

go_build.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/bash
2+
set -e
3+
for OS_ARCH in linux/amd64 linux/ppc64le linux/s390x
4+
do
5+
declare OS=$(echo $OS_ARCH | cut -f1 -d/)
6+
declare ARCH=$(echo $OS_ARCH | cut -f2 -d/)
7+
GOOS="$OS" CGO_ENABLED=0 GOARCH="$ARCH" go build -o ./build/appsody-controller-"$OS_ARCH" -ldflags "-X main.VERSION=$1"
8+
done

0 commit comments

Comments
 (0)