From f7b9dfc10ad9b9dcc8b3013adef6c82e84c6c108 Mon Sep 17 00:00:00 2001 From: Daniel Apatin Date: Tue, 23 Jul 2024 08:25:08 +0300 Subject: [PATCH] build multiarch, publish to hub.docker.com --- Dockerfile | 10 ++++++---- Makefile | 34 ++++++++++++++++++++++++++++++++++ README.md | 4 ++-- docker-compose.yml | 2 +- 4 files changed, 43 insertions(+), 7 deletions(-) create mode 100644 Makefile diff --git a/Dockerfile b/Dockerfile index 3e53e84..4f3cc50 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,7 @@ -FROM golang:alpine as builder +FROM --platform=$BUILDPLATFORM golang:alpine AS builder -ARG BUILD_ARCH +ARG TARGETOS +ARG TARGETARCH RUN apk update && apk add --no-cache ca-certificates && update-ca-certificates @@ -9,12 +10,13 @@ COPY . . COPY config.json /config.json RUN mkdir -p /share/domofon && touch /share/domofon/account.json && chmod 777 /share/domofon/account.json -RUN CGO_ENABLED=0 go build -mod=vendor -ldflags='-w -s -extldflags "-static"' -a -o /go/bin/domru . +RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -mod=vendor -ldflags='-w -s -extldflags "-static"' -a -o /go/bin/domru . FROM scratch ARG BUILD_DATE ARG BUILD_REF +ARG TARGETARCH COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ COPY --from=builder /etc/passwd /etc/passwd @@ -31,7 +33,7 @@ ENTRYPOINT ["/go/bin/domru"] LABEL \ io.hass.name="Domofon addon" \ io.hass.description="Domofon addon" \ - io.hass.arch="${BUILD_ARCH}" \ + io.hass.arch=${TARGETARCH} \ io.hass.type="addon" \ maintainer="ad " \ org.label-schema.description="Domofon addon" \ diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..3b157ea --- /dev/null +++ b/Makefile @@ -0,0 +1,34 @@ +.EXPORT_ALL_VARIABLES: +.DEFAULT_GOAL := default +DOCKER_SCAN_SUGGEST = false +CWD = $(shell pwd) +SRC_DIRS := . +GOCACHE ?= $$(pwd)/.go/cache +BUILD_VERSION=$(shell cat config.json | awk 'BEGIN { FS="\""; RS="," }; { if ($$2 == "version") {print $$4} }') +IMAGE ?= danielapatin/domru:${BUILD_VERSION} + +export DOCKER_CLI_EXPERIMENTAL=enabled + +.PHONY: build # Build the container image +build: + @docker buildx create --use --name=crossplat --node=crossplat && \ + docker buildx build \ + --build-arg="BUILD_VERSION=${BUILD_VERSION}" \ + --output "type=docker,push=false" \ + --tag $(IMAGE) \ + --tag danielapatin/domru:latest \ + . + +.PHONY: publish # Push the image to the remote registry +publish: + @docker buildx create --use --name=crossplat --node=crossplat && \ + docker buildx build \ + --platform linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64 \ + --build-arg="BUILD_VERSION=${BUILD_VERSION}" \ + --output "type=image,push=true" \ + --tag $(IMAGE) \ + --tag danielapatin/domru:latest \ + . + +lint: + @docker run --rm -t -w $(CWD) -v $(CURDIR):$(CWD) -e GOFLAGS=-mod=vendor golangci/golangci-lint:latest golangci-lint run -v diff --git a/README.md b/README.md index 4a48c59..86bde07 100644 --- a/README.md +++ b/README.md @@ -25,9 +25,9 @@ domru -login=1234567890 -operator=2 -token=... -refresh=... -port=18000 ```shell cp example.accounts.json accounts.json -docker build -t ad/domru:latest . +make build -docker run --name domru --rm -p 8080:18000 -e DOMRU_PORT=18000 -v $(pwd)/accounts.json:/share/domofon/account.json ad/domru:latest +docker run --name domru --rm -p 8080:18000 -e DOMRU_PORT=18000 -v $(pwd)/accounts.json:/share/domofon/account.json danielapatin/domru:latest open http://localhost:8080/login enter phone number in format 79xxxxxxxxx diff --git a/docker-compose.yml b/docker-compose.yml index 85cf9dd..74d4f37 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -5,7 +5,7 @@ services: build: context: "." dockerfile: Dockerfile - image: ad/domru:latest + image: danielapatin/domru:latest container_name: domru restart: always networks: