diff --git a/.gitignore b/.gitignore index e6276f2..22c0522 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ /controller /build /package -.vscode/ \ No newline at end of file +.vscode/ +.DS_Store diff --git a/.travis.yml b/.travis.yml index 5ffeade..2f9df2e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,6 +12,13 @@ go_import_path: github.com/appsody/controller services: - docker +#Install later docker version +before_install: + - 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 + # skip because dependencies are baked in vendor dir install: true @@ -35,7 +42,7 @@ deploy: repo: appsody/controller - provider: script skip_cleanup: true - script: bash ./build.sh + script: ./build.sh on: tags: true repo: appsody/controller diff --git a/Dockerfile b/Dockerfile index 6afc958..422eae7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ FROM busybox - -COPY ./package/appsody-controller /appsody-controller +ARG TARGETPLATFORM +COPY ./package/appsody-controller-$TARGETPLATFORM /appsody-controller RUN chmod +x /appsody-controller WORKDIR / CMD ["cp","/appsody-controller","/.appsody/appsody-controller"] \ No newline at end of file diff --git a/Makefile b/Makefile index a61e219..b630225 100644 --- a/Makefile +++ b/Makefile @@ -51,12 +51,13 @@ clean: ## Removes existing build artifacts in order to get a fresh build .PHONY: build build: ## Build binary for linux stores it in the build/ dir - GOOS=linux CGO_ENABLED=0 GOARCH=amd64 go build -o $(BUILD_PATH)/$(COMMAND) -ldflags "-X main.VERSION=$(VERSION)" + chmod u+r+x go_build.sh + ./go_build.sh $(VERSION) .PHONY: package package: build ## Build the linux binary and stores it in package/ dir mkdir -p $(PACKAGE_PATH) - cp -p $(BUILD_PATH)/$(COMMAND) $(PACKAGE_PATH)/ + cp -ap $(BUILD_PATH)/. $(PACKAGE_PATH)/ # Auto documented help from http://marmelab.com/blog/2016/02/29/auto-documented-makefile.html .PHONY: help diff --git a/build.sh b/build.sh index 0837199..4bde200 100755 --- a/build.sh +++ b/build.sh @@ -1,7 +1,10 @@ #!/bin/bash - - set -e echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin -docker build -t $DOCKER_ORG/init-controller:$TRAVIS_TAG -t $DOCKER_ORG/init-controller:latest . -docker push $DOCKER_ORG/init-controller +# enables experimental daemon for docker buildx: https://docs.docker.com/buildx/working-with-buildx/ +# minimum docker version required for buildx is v19.03 +export DOCKER_CLI_EXPERIMENTAL=enabled +docker run --rm --privileged multiarch/qemu-user-static --reset -p yes +docker buildx create --name mybuilder +docker buildx use mybuilder +docker buildx build -t $DOCKER_ORG/init-controller:$TRAVIS_TAG -t $DOCKER_ORG/init-controller:latest --platform=linux/amd64,linux/ppc64le,linux/s390x . --push \ No newline at end of file diff --git a/go_build.sh b/go_build.sh new file mode 100755 index 0000000..f6bcc04 --- /dev/null +++ b/go_build.sh @@ -0,0 +1,8 @@ +#!/bin/bash +set -e +for OS_ARCH in linux/amd64 linux/ppc64le linux/s390x +do + declare OS=$(echo $OS_ARCH | cut -f1 -d/) + declare ARCH=$(echo $OS_ARCH | cut -f2 -d/) + GOOS="$OS" CGO_ENABLED=0 GOARCH="$ARCH" go build -o ./build/appsody-controller-"$OS_ARCH" -ldflags "-X main.VERSION=$1" +done