Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 43 additions & 20 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Checkout code
uses: actions/checkout@v2

- name: Run tests
run: make
- name: Test build
run: make build

# Push image to GitHub Packages.
# See also https://docs.docker.com/docker-hub/builds/
Expand All @@ -42,18 +43,8 @@ jobs:
packages: write

steps:
- uses: actions/checkout@v2

- name: Build app
run: make build

- name: Build image
run: docker build . --file Dockerfile --tag $IMAGE_NAME --label "runnumber=${GITHUB_RUN_ID}"

- name: Log into registry
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin

- name: Push image
- name: Set up environment
id: setup
run: |
IMAGE_ID=ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME

Expand All @@ -69,8 +60,40 @@ jobs:
# Use Docker `latest` tag convention
[ "$VERSION" == "master" ] && VERSION=latest

echo IMAGE_ID=$IMAGE_ID
echo VERSION=$VERSION

docker tag $IMAGE_NAME $IMAGE_ID:$VERSION
docker push $IMAGE_ID:$VERSION
TAGS="${IMAGE_ID}:${VERSION}"

echo ::set-output name=tags::${TAGS}

- name: Checkout code
uses: actions/checkout@v2

- name: Set up QEMU
id: qemu
uses: docker/setup-qemu-action@v1
with:
platforms: arm64

- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v1
with:
install: true

- name: List available platforms
run: echo ${{ steps.buildx.outputs.platforms }}

- name: Login to GitHub Container Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push
uses: docker/build-push-action@v2
with:
context: .
file: ./Dockerfile
platforms: linux/amd64,linux/arm64
tags: ${{ steps.setup.outputs.tags }}
push: true
10 changes: 9 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
FROM golang:1.17 AS builder

WORKDIR /go/src/github.com/rhobs/prometheus-example-app
COPY . /go/src/github.com/rhobs/prometheus-example-app

RUN make build

FROM quay.io/prometheus/busybox:latest

ADD prometheus-example-app /bin/prometheus-example-app
COPY --from=builder /go/src/github.com/rhobs/prometheus-example-app/prometheus-example-app \
/bin/prometheus-example-app

ENTRYPOINT ["/bin/prometheus-example-app"]
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ LDFLAGS="-X main.appVersion=$(VERSION)"

.PHONY : all build image

all: build image
all: build

build:
CGO_ENABLED=0 go build -ldflags=$(LDFLAGS) -o prometheus-example-app --installsuffix cgo main.go

image: build
docker build -t ghcr.io/rhobs/$(IMAGE_NAME):$(VERSION) .
image:
docker build -t "ghcr.io/rhobs/$(IMAGE_NAME):$(VERSION)" .