Skip to content

Commit

Permalink
Build multi-arch docker images
Browse files Browse the repository at this point in the history
  • Loading branch information
jayme-github committed Apr 13, 2021
1 parent 2e6057d commit 0f7bb25
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
**
!build/fritzbox_smarthome_exporter.linux.amd64
!build/fritzbox_smarthome_exporter.linux.*
17 changes: 14 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
language: go
dist: focal
sudo: required

env:
Expand All @@ -20,16 +21,26 @@ matrix:
allow_failures:
- go: tip

before_install:
- mkdir -p ~/.docker/cli-plugins/
- curl --silent -L "https://github.com/docker/buildx/releases/download/v0.3.0/buildx-v0.3.0.linux-amd64" > ~/.docker/cli-plugins/docker-buildx
- chmod a+x ~/.docker/cli-plugins/docker-buildx

install:
- go mod download
- go get github.com/mitchellh/gox

script:
- go vet $(go list ./... | grep -v /vendor/)
- go test -v ./...
- if [ "${LATEST}" = "true" ]; then gox -os="darwin" -os="linux" -os="windows" -arch="amd64" -arch="arm64" -osarch="linux/386" -osarch="linux/arm" -osarch="windows/386"
-output="build/fritzbox_smarthome_exporter.{{.OS}}.{{.Arch}}" -ldflags "-extldflags \"-static\" -X main.Rev=`git rev-parse --short HEAD`" -verbose ./...; fi
- if [ "${LATEST}" = "true" -a -n "${TRAVIS_TAG}" ]; then docker build -t "jaymedh/fritzbox_smarthome_exporter:${TRAVIS_TAG}" .; fi
- if [ "${LATEST}" = "true" ]; then
gox -os="darwin" -os="linux" -os="windows" -arch="amd64" -arch="arm64" -osarch="linux/386" -osarch="linux/arm" -osarch="windows/386"
-output="build/fritzbox_smarthome_exporter.{{.OS}}.{{.Arch}}" -ldflags "-extldflags \"-static\" -X main.Rev=`git rev-parse --short HEAD`" -verbose ./...;
fi
- if [ "${LATEST}" = "true" -a -n "${TRAVIS_TAG}" ]; then
docker buildx create --use;
docker buildx build --platform linux/amd64,linux/arm64,linux/arm,linux/386 -t "jaymedh/fritzbox_smarthome_exporter:${TRAVIS_TAG}" .;
fi

deploy:
- provider: releases
Expand Down
7 changes: 5 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
FROM scratch

COPY build/fritzbox_smarthome_exporter.linux.amd64 /
ARG TARGETOS
ARG TARGETARCH

COPY build/fritzbox_smarthome_exporter.${TARGETOS}.${TARGETARCH} /fritzbox_smarthome_exporter

EXPOSE 9103

ENTRYPOINT ["/fritzbox_smarthome_exporter.linux.amd64"]
ENTRYPOINT ["/fritzbox_smarthome_exporter"]
2 changes: 1 addition & 1 deletion docker_push.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/bash
echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
docker push "jaymedh/fritzbox_smarthome_exporter:${TRAVIS_TAG}"
docker buildx build --push --platform linux/amd64,linux/arm64,linux/arm,linux/386 -t "jaymedh/fritzbox_smarthome_exporter:${TRAVIS_TAG}" .

0 comments on commit 0f7bb25

Please sign in to comment.