Add multi-arch builds
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
IamTheFij 2019-06-07 15:40:04 -07:00
parent b5a19bb1d2
commit 44a54f1c7f
5 changed files with 157 additions and 37 deletions

View File

@ -1,28 +1,87 @@
platform: ${platform} kind: pipeline
name: test
workspace: workspace:
base: /go base: /go/src/dockron
pipeline: steps:
build: - name: build
image: golang:1.10 image: golang:1.11
commands: commands:
- go version
- go env
- go get -u github.com/golang/dep/cmd/dep - go get -u github.com/golang/dep/cmd/dep
- make build - make build
# publish:
# image: plugins/docker:${docker_tag}
# repo: iamthefij/dockron
# secrets:
# - docker_username
# - docker_password
# tag:
# - ${docker_tag}
matrix: ---
include: kind: pipeline
- platform: linux/amd64 name: publish
docker_tag: latest
# - platform: linux/arm depends_on:
# docker_tag: linux-arm - test
trigger:
event:
- push
- tag
refs:
- refs/heads/master
- refs/tags/v*
workspace:
base: /go/src/dockron
steps:
- name: build
image: golang:1.11
commands:
- go get -u github.com/golang/dep/cmd/dep
- make build-all-static
- name: push image - arm
image: plugins/docker
settings:
repo: iamthefij/dockron
auto_tag: true
auto_tag_suffix: linux-arm
username:
from_secret: docker_username
password:
from_secret: docker_password
build_args:
- ARCH=arm
- REPO=arm32v6
- name: push image - arm64
image: plugins/docker
settings:
repo: iamthefij/dockron
auto_tag: true
auto_tag_suffix: linux-arm64
username:
from_secret: docker_username
password:
from_secret: docker_password
build_args:
- ARCH=arm
- REPO=arm32v6
- name: push image - amd64
image: plugins/docker
settings:
repo: iamthefij/dockron
auto_tag: true
auto_tag_suffix: linux-amd64
username:
from_secret: docker_username
password:
from_secret: docker_password
- 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

1
.gitignore vendored
View File

@ -26,5 +26,6 @@ _testmain.go
# Output # Output
dockron dockron
dockron-linux-*
# deps # deps
vendor/ vendor/

View File

@ -1,16 +1,21 @@
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/
# COPY ./Gopkg.* /go/src/app/
# RUN dep ensure --vendor-only
#
# COPY ./main.go /go/src/app/
#
# RUN CGO_ENABLED=0 GOOS=linux GOARCH=${ARCH} go build -a -installsuffix nocgo -o dockron .
RUN go get -u github.com/golang/dep/cmd/dep FROM ${REPO}/busybox:latest
WORKDIR /go/src/app/
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
WORKDIR /root/ WORKDIR /root/
COPY --from=builder /go/src/app/dockron . # COPY --from=builder /go/src/app/dockron .
ARG ARCH=amd64
COPY ./dockron-linux-${ARCH} ./dockron
CMD [ "./dockron" ] CMD [ "./dockron" ]

View File

@ -1,4 +1,4 @@
DOCKER_TAG ?= dockron-dev DOCKER_TAG ?= dockron-dev-${USER}
.PHONY: default .PHONY: default
default: build default: build
@ -20,6 +20,18 @@ dockron: vendor
.PHONY: build .PHONY: build
build: dockron build: dockron
dockron-linux-amd64: vendor
GOARCH=amd64 CGO_ENABLED=0 GOOS=linux go build -a -installsuffix nocgo -o dockron-linux-amd64
dockron-linux-arm: vendor
GOARCH=arm CGO_ENABLED=0 GOOS=linux go build -a -installsuffix nocgo -o dockron-linux-arm
dockron-linux-arm64: vendor
GOARCH=arm64 CGO_ENABLED=0 GOOS=linux go build -a -installsuffix nocgo -o dockron-linux-arm64
.PHONY: build-all-static
build-all-static: dockron-linux-amd64 dockron-linux-arm dockron-linux-arm64
# Cleans all build artifacts # Cleans all build artifacts
.PHONY: clean .PHONY: clean
clean: clean:
@ -37,8 +49,26 @@ dep-update:
.PHONY: docker-build .PHONY: docker-build
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 .PHONY: docker-run
docker-run: docker-run: docker-build
docker run --rm -v /var/run/docker.sock:/var/run/docker.sock --name $(DOCKER_TAG)-run $(DOCKER_TAG) 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

25
manifest.tmpl Normal file
View File

@ -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