Skip to content

Commit

Permalink
Change behavior of Docker tags (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
xperimental authored Jan 8, 2023
1 parent fd1192d commit dd2c509
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 34 deletions.
35 changes: 26 additions & 9 deletions .github/workflows/package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ on:
release:
types:
- published
pull_request:
branches:
- master
jobs:
test:
runs-on: ubuntu-latest
Expand All @@ -29,22 +32,36 @@ jobs:
with:
fetch-depth: 0
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v1
uses: docker/setup-buildx-action@v2
- name: Login to GitHub Container Registry
uses: docker/login-action@v1
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Login to Docker hub
uses: docker/login-action@v1
uses: docker/login-action@v2
with:
username: xperimental
password: ${{ secrets.DOCKER_TOKEN }}
- name: Build image
run: make all-images
env:
GITHUB_REF: ${{ github.ref }}
- name: Docker Metadata
id: meta
uses: docker/metadata-action@v4
with:
images: |
ghcr.io/xperimental/netatmo-exporter
xperimental/netatmo-exporter
tags: |
type=semver,pattern={{version}}
type=ref,event=branch
type=ref,event=pr
- name: Build and push Docker images
uses: docker/build-push-action@v3
with:
context: .
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: linux/amd64,linux/arm64
13 changes: 0 additions & 13 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,6 @@ on:
branches:
- master
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Setup Go
uses: actions/setup-go@v3
with:
go-version-file: go.mod
- name: Build and Test
run: make
lint:
runs-on: ubuntu-latest
steps:
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ This changelog contains the changes made between releases. The versioning follow

## Unreleased

### Changed

- `latest` Docker tag now points to most recent release and `master` points to the build from the default branch

## [1.5.0] - 2022-12-06

### Added
Expand Down
12 changes: 9 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
FROM golang:1.19.3-alpine AS builder
FROM --platform=$BUILDPLATFORM golang:1.19.3-alpine AS builder

ARG TARGETOS
ARG TARGETARCH

ENV GOOS=$TARGETOS
ENV GOARCH=$TARGETARCH

RUN apk add --no-cache make git bash

Expand All @@ -9,9 +15,9 @@ RUN go mod download
RUN go mod verify

COPY . /build/
RUN make
RUN make build-binary

FROM busybox
FROM --platform=$TARGETPLATFORM busybox
LABEL maintainer="Robert Jacob <[email protected]>"

COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
Expand Down
12 changes: 4 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,8 @@ GO_CMD := CGO_ENABLED=0 $(GO)
GIT_VERSION := $(shell git describe --tags --dirty)
VERSION := $(GIT_VERSION:v%=%)
GIT_COMMIT := $(shell git rev-parse HEAD)
GITHUB_REF ?= refs/heads/master
DOCKER_TAG != if [[ "$(GITHUB_REF)" == "refs/heads/master" ]]; then \
echo "latest"; \
else \
echo "$(VERSION)"; \
fi
DOCKER_REPO ?= xperimental/netatmo-exporter
DOCKER_TAG ?= dev

.PHONY: all
all: test build-binary
Expand All @@ -28,11 +24,11 @@ build-binary:

.PHONY: image
image:
docker buildx build -t "xperimental/netatmo-exporter:$(DOCKER_TAG)" --load .
docker buildx build -t "ghcr.io/$(DOCKER_REPO):$(DOCKER_TAG)" --load .

.PHONY: all-images
all-images:
docker buildx build -t "ghcr.io/xperimental/netatmo-exporter:$(DOCKER_TAG)" -t "xperimental/netatmo-exporter:$(DOCKER_TAG)" --platform linux/amd64,linux/arm64 --push .
docker buildx build -t "ghcr.io/$(DOCKER_REPO):$(DOCKER_TAG)" -t "docker.io/$(DOCKER_REPO):$(DOCKER_TAG)" --platform linux/amd64,linux/arm64 --push .

.PHONY: clean
clean:
Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ The exporter is available as a Docker image both on DockerHub and GitHub:
- [`ghcr.io/xperimental/netatmo-exporter`](https://github.com/xperimental/netatmo-exporter/pkgs/container/netatmo-exporter)
- [`xperimental/netatmo-exporter`](https://hub.docker.com/r/xperimental/netatmo-exporter/)

In addition to the `latest` tag which points to the version currently in the `master` branch, tagged versions are also available.
The following tags are available:

- `x.y.z` pointing to the release with that version
- `latest` pointing to the most recent released version
- `master` pointing to the latest build from the default branch

### Build from source

Expand Down

0 comments on commit dd2c509

Please sign in to comment.