From 7c6e536ec3beb94cd75be4fb0b4fe6571891b643 Mon Sep 17 00:00:00 2001 From: Ian Fijolek Date: Fri, 7 Jun 2019 15:40:04 -0700 Subject: [PATCH] Try out multi arch builds --- .drone.yml | 146 +++++++++++++++++++++++++++++++++++++++++--------- Dockerfile | 10 ++-- Makefile | 26 +++++++-- manifest.tmpl | 25 +++++++++ 4 files changed, 175 insertions(+), 32 deletions(-) create mode 100644 manifest.tmpl diff --git a/.drone.yml b/.drone.yml index d55cc4a..f0af2cb 100644 --- a/.drone.yml +++ b/.drone.yml @@ -1,28 +1,124 @@ -platform: ${platform} +# kind: pipeline +# name: build +# +# workspace: +# base: /go +# +# steps: +# - name: build +# image: golang:1.11 +# commands: +# - go version +# - go env +# - go get -u github.com/golang/dep/cmd/dep +# - make build -workspace: - base: /go +kind: pipeline +name: linux-amd64 -pipeline: - build: - image: golang:1.10 - commands: - - go version - - go env - - go get -u github.com/golang/dep/cmd/dep - - make build - # publish: - # image: plugins/docker:${docker_tag} - # repo: iamthefij/dockron - # secrets: - # - docker_username - # - docker_password - # tag: - # - ${docker_tag} +trigger: + event: + - push + - tag + # ref: + # - refs/heads/master + # - refs/tags/v* -matrix: - include: - - platform: linux/amd64 - docker_tag: latest - # - platform: linux/arm - # docker_tag: linux-arm +steps: + + - name: build + image: plugins/docker + settings: + repo: iamthefij/multiarch-pipeline-test + auto_tag: true + auto_tag_suffix: linux-amd64 + username: + from_secret: docker_username + password: + from_secret: docker_password + +--- +kind: pipeline +name: linux-arm + +trigger: + event: + - push + - tag + # ref: + # - refs/heads/master + # - refs/tags/v* + +steps: + + - name: build + image: plugins/docker + settings: + repo: iamthefij/multiarch-pipeline-test + auto_tag: true + auto_tag_suffix: linux-arm + username: + from_secret: docker_username + password: + from_secret: docker_password + build_args: + - ARCH=arm + - REPO=arm32v6 + +--- +kind: pipeline +name: linux-arm64 + +trigger: + event: + - push + - tag + # ref: + # - refs/heads/master + # - refs/tags/v* + +steps: + + - name: build + image: plugins/docker + settings: + repo: iamthefij/multiarch-pipeline-test + auto_tag: true + auto_tag_suffix: linux-arm64 + username: + from_secret: docker_username + password: + from_secret: docker_password + build_args: + - ARCH=arm64 + - REPO=arm64v8 + +# --- +# kind: pipeline +# name: manifest +# +# depends_on: +# - linux-amd64 +# - linux-arm +# - linux-arm64 +# +# trigger: +# event: +# - push +# - tag +# ref: +# - refs/heads/master +# - refs/tags/v* +# +# steps: +# - name: publish manifest +# image: plugins/manifest +# settings: +# spec: manifest.tmpl +# auto_tag: true +# ignore_missing: true +# username: +# from_secret: docker_username +# password: +# from_secret: docker_password +# diff --git a/Dockerfile b/Dockerfile index 817a890..6acbcac 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,7 @@ -FROM golang:1.10 AS builder +ARG REPO=library +FROM golang:1.11-alpine AS builder +RUN apk add --no-cache git RUN go get -u github.com/golang/dep/cmd/dep WORKDIR /go/src/app/ @@ -7,9 +9,11 @@ COPY ./Gopkg.* /go/src/app/ RUN dep ensure --vendor-only COPY ./main.go /go/src/app/ -RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix nocgo -o dockron . -FROM busybox:latest +ARG ARCH=amd64 +RUN CGO_ENABLED=0 GOOS=linux GOARCH=${ARCH} go build -a -installsuffix nocgo -o dockron . + +FROM ${REPO}/busybox:latest WORKDIR /root/ COPY --from=builder /go/src/app/dockron . diff --git a/Makefile b/Makefile index e24a72f..b51510c 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -DOCKER_TAG ?= dockron-dev +DOCKER_TAG ?= dockron-dev-${USER} .PHONY: default default: build @@ -37,8 +37,26 @@ dep-update: .PHONY: docker-build docker-build: - docker build -t $(DOCKER_TAG) . + docker build . -t ${DOCKER_TAG}-linux-amd64 + +# Cross build for arm architechtures +.PHONY: docker-cross-build-arm +docker-cross-build-arm: + docker build --build-arg REPO=arm32v6 --build-arg ARCH=arm . -t ${DOCKER_TAG}-linux-arm + +.PHONY: docker-cross-build-arm +docker-cross-build-arm64: + docker build --build-arg REPO=arm64v8 --build-arg ARCH=arm64 . -t ${DOCKER_TAG}-linux-arm64 .PHONY: docker-run -docker-run: - docker run --rm -v /var/run/docker.sock:/var/run/docker.sock --name $(DOCKER_TAG)-run $(DOCKER_TAG) +docker-run: docker-build + docker run --rm -v /var/run/docker.sock:/var/run/docker.sock --name $(DOCKER_TAG)-run $(DOCKER_TAG)-linux-amd64 + +# Cross run on host architechture +.PHONY: docker-cross-run-arm +docker-cross-run-arm: docker-cross-build-arm + docker run --rm -v /var/run/docker.sock:/var/run/docker.sock --name $(DOCKER_TAG)-run ${DOCKER_TAG}-linux-arm + +.PHONY: docker-cross-run-arm64 +docker-cross-run-arm64: docker-cross-build-arm64 + docker run --rm -v /var/run/docker.sock:/var/run/docker.sock --name $(DOCKER_TAG)-run ${DOCKER_TAG}-linux-arm64 diff --git a/manifest.tmpl b/manifest.tmpl new file mode 100644 index 0000000..064b947 --- /dev/null +++ b/manifest.tmpl @@ -0,0 +1,25 @@ +image: iamthefij/dockron:{{#if build.tag}}{{trimPrefix "v" build.tag}}{{else}}latest{{/if}} +{{#if build.tags}} +tags: +{{#each build.tags}} + - {{this}} +{{/each}} +{{/if}} +manifests: + - + image: iamthefij/dockron:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}linux-amd64 + platform: + architecture: amd64 + os: linux + - + image: iamthefij/dockron:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}linux-arm64 + platform: + architecture: arm64 + os: linux + variant: v8 + - + image: iamthefij/dockron:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}linux-arm + platform: + architecture: arm + os: linux + variant: v7