Skip to content

Commit 0362d32

Browse files
authored
Adds Dockerfile and Docker Image Creation (#35)
1 parent 4c00a26 commit 0362d32

File tree

2 files changed

+127
-0
lines changed

2 files changed

+127
-0
lines changed

.github/workflows/container.yaml

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
name: Containers
2+
on:
3+
push:
4+
branches:
5+
- main
6+
tags:
7+
- "v*"
8+
pull_request:
9+
branches:
10+
- main
11+
12+
jobs:
13+
# Honu Image Build
14+
honu:
15+
name: Honu
16+
runs-on: ubuntu-latest
17+
steps:
18+
- name: Checkout Code
19+
uses: actions/checkout@v4
20+
21+
- name: Set Environment
22+
id: vars
23+
run: |
24+
echo "tag=${GITHUB_REF#refs/*/}" >> $GITHUB_OUTPUT
25+
echo "revision=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
26+
27+
- name: Docker Metadata
28+
id: meta
29+
uses: docker/metadata-action@v5
30+
with:
31+
# list of Docker images to use as basenames for tags
32+
# this should be configured for each container built
33+
images: |
34+
rotationalio/honu
35+
gcr.io/rotationalio-habanero/honu
36+
tags: |
37+
type=semver,pattern={{raw}}
38+
type=semver,pattern={{version}}
39+
type=semver,pattern={{major}}.{{minor}}
40+
type=sha,prefix=,suffix=,format=short
41+
42+
- name: Setup QEMU
43+
uses: docker/setup-qemu-action@v3
44+
45+
- name: Setup Docker Buildx
46+
id: buildx
47+
uses: docker/setup-buildx-action@v3
48+
49+
- name: Login to DockerHub
50+
if: github.event_name != 'pull_request'
51+
uses: docker/login-action@v3
52+
with:
53+
username: ${{ secrets.DOCKERHUB_USERNAME }}
54+
password: ${{ secrets.DOCKERHUB_ACCESS_TOKEN }}
55+
56+
- name: Login to GCR
57+
if: github.event_name != 'pull_request'
58+
uses: docker/login-action@v3
59+
with:
60+
registry: gcr.io
61+
username: _json_key
62+
password: ${{ secrets.GCR_SERVICE_ACCOUNT }}
63+
64+
- name: Build and push
65+
id: docker_build
66+
uses: docker/build-push-action@v5
67+
with:
68+
context: .
69+
file: ./Dockerfile
70+
push: ${{ github.event_name != 'pull_request' }}
71+
tags: ${{ steps.meta.outputs.tags }}
72+
labels: ${{ steps.meta.outputs.labels }}
73+
platforms: linux/amd64,linux/arm64
74+
build-args: |
75+
GIT_REVISION=${{ steps.vars.outputs.revision }}

Dockerfile

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Dynamic Builds
2+
ARG BUILDER_IMAGE=golang:1.23-bookworm
3+
ARG FINAL_IMAGE=debian:bookworm-slim
4+
5+
# Build stage
6+
FROM --platform=${BUILDPLATFORM} ${BUILDER_IMAGE} AS builder
7+
8+
# Build Args
9+
ARG GIT_REVISION=""
10+
11+
# Platform args
12+
ARG TARGETOS
13+
ARG TARGETARCH
14+
15+
# Ensure ca-certificates are up to date
16+
RUN update-ca-certificates
17+
18+
# Use modules for dependencies
19+
WORKDIR $GOPATH/src/github.com/rotationalio/honu
20+
21+
COPY go.mod .
22+
COPY go.sum .
23+
24+
ENV CGO_ENABLED=0
25+
ENV GO111MODULE=on
26+
RUN go mod download
27+
RUN go mod verify
28+
29+
# Copy package
30+
COPY . .
31+
32+
# Build binary
33+
RUN GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build \
34+
-ldflags="-X 'github.com/rotationalio/honu/pkg.GitVersion=${GIT_REVISION}'" \
35+
-o /go/bin/honudb \
36+
./cmd/honudb
37+
38+
# Final Stage
39+
FROM --platform=${BUILDPLATFORM} ${FINAL_IMAGE} AS final
40+
41+
LABEL maintainer="Rotational Labs <[email protected]>"
42+
LABEL description="Honu distributed database replica instance"
43+
44+
# Ensure ca-certificates are up to date
45+
RUN set -x && apt-get update && \
46+
DEBIAN_FRONTEND=noninteractive apt-get install -y ca-certificates && \
47+
rm -rf /var/lib/apt/lists/*
48+
49+
# Copy the binary to the production image from the builder stage
50+
COPY --from=builder /go/bin/honudb /usr/local/bin/honudb
51+
52+
CMD [ "/usr/local/bin/honudb", "serve" ]

0 commit comments

Comments
 (0)