Skip to content

Commit

Permalink
Docker: build multiarchitecture images
Browse files Browse the repository at this point in the history
  • Loading branch information
RoEdAl committed Feb 14, 2025
1 parent eb53439 commit d396fd0
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 22 deletions.
27 changes: 19 additions & 8 deletions .github/workflows/docker-ghcrio.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
name: Upload Docker images to ghcr.io
name: Upload Docker images to GitHub Container Registry (ghcr.io)

on:
push:
branches: [ master ]
branches: [ master, main ]
tags: [ 'v*' ]
pull_request:
branches: [ master ]
branches: [ master, main ]

jobs:
docker:
name: Build image
name: Build images
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
with:
platforms: arm,arm64
cache-image: false
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
Expand All @@ -28,19 +35,23 @@ jobs:
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}.{{minor}}.{{patch}}
- name: Login to ghcr.io
env:
DOCKER_METADATA_ANNOTATIONS_LEVELS: manifest,index
- name: Login to GitHub Container Registry
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push
id: docker_build
uses: docker/build-push-action@v6
with:
# push for non-pr events
push: ${{ github.event_name != 'pull_request' }}
context: .
platforms: linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
annotations: ${{ steps.meta.outputs.annotations }}
cache-from: type=gha
cache-to: type=gha,mode=max
39 changes: 25 additions & 14 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,23 +1,34 @@
FROM golang:1.23-alpine AS build
FROM golang:alpine AS build
ARG TARGETARCH

COPY . /usr/local/src/go-carbon
RUN apk add --update git make bash \
&& cd /usr/local/src/go-carbon \
&& make go-carbon \
&& chmod +x go-carbon && cp -fv go-carbon /tmp
RUN apk add --update git make bash gcc musl-dev

FROM alpine:3
USER nobody:nogroup
WORKDIR /usr/local/src/go-carbon
COPY --chown=nobody:nogroup . .
RUN --mount=type=cache,id=go-cache,target=/.cache,sharing=locked,uid=65534,gid=65534 make go-carbon
RUN --mount=type=cache,id=go-cache,target=/.cache,sharing=locked,uid=65534,gid=65534 <<EOT
if [ "${TARGETARCH:-unknown}" = "amd64" ]; then
make run-test COMMAND="test -race"
else
make run-test COMMAND="test" || true
fi
EOT

RUN addgroup -S carbon && adduser -S carbon -G carbon \
&& mkdir -p /var/lib/graphite/whisper /var/lib/graphite/dump /var/lib/graphite/tagging /var/log/go-carbon /etc/go-carbon/ \
&& chown -R carbon:carbon /var/lib/graphite/ /var/log/go-carbon
FROM alpine:latest

COPY --from=build /tmp/go-carbon /usr/sbin/go-carbon
ADD go-carbon.conf.example /etc/go-carbon/go-carbon.conf
RUN --network=none addgroup -S carbon && adduser -S carbon -G carbon \
&& mkdir -p /var/lib/graphite/whisper /etc/go-carbon/ \
&& chown -R carbon:carbon /var/lib/graphite/

COPY --chown=0:0 --from=build /usr/local/src/go-carbon/go-carbon /usr/sbin/go-carbon
ADD go-carbon.docker.conf /etc/go-carbon/go-carbon.conf
ADD deploy/storage*.conf /etc/go-carbon/
RUN --network=none /usr/sbin/go-carbon -config-print-default > /etc/go-carbon/go-carbon.default.conf

USER carbon
CMD ["/usr/sbin/go-carbon", "-daemon=false", "-config", "/etc/go-carbon/go-carbon.conf"]
ENTRYPOINT ["/usr/sbin/go-carbon"]
CMD ["-config", "/etc/go-carbon/go-carbon.conf"]

EXPOSE 2003 2004 7002 7003 7007 8080 2003/udp
EXPOSE 2003/tcp 2003/udp 8080
VOLUME /var/lib/graphite /etc/go-carbon
45 changes: 45 additions & 0 deletions go-carbon.docker.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
[whisper]
enabled = true
data-dir = "/var/lib/graphite/whisper"
schemas-file = "/etc/go-carbon/storage-schemas.conf"
aggregation-file = "/etc/go-carbon/storage-aggregation.conf"
sparse-create = true

[cache]
max-size = 1000000
write-strategy = "noop"
bloom-size = 0

[udp]
listen = ":2003"
enabled = true
buffer-size = 0

[tcp]
listen = ":2003"
enabled = true
buffer-size = 0

[carbonserver]
listen = ":8080"
enabled = true

[pickle]
enabled = false

[grpc]
enabled = false

[carbonlink]
enabled = false

[dump]
enabled = false

[[logging]]
logger = ""
file = "stdout"
level = "error"
encoding = "console"
encoding-time = ""
encoding-duration = ""

0 comments on commit d396fd0

Please sign in to comment.