Skip to content

Commit

Permalink
build multiarch, publish to hub.docker.com
Browse files Browse the repository at this point in the history
  • Loading branch information
ad committed Jul 23, 2024
1 parent 6f6e001 commit f7b9dfc
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 7 deletions.
10 changes: 6 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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
Expand All @@ -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 <[email protected]>" \
org.label-schema.description="Domofon addon" \
Expand Down
34 changes: 34 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ services:
build:
context: "."
dockerfile: Dockerfile
image: ad/domru:latest
image: danielapatin/domru:latest
container_name: domru
restart: always
networks:
Expand Down

0 comments on commit f7b9dfc

Please sign in to comment.