diff --git a/.github/workflows/containers.yaml b/.github/workflows/containers.yaml new file mode 100644 index 0000000..f5ee592 --- /dev/null +++ b/.github/workflows/containers.yaml @@ -0,0 +1,76 @@ +name: Containers +on: + push: + branches: + - main + tags: + - "v*" + pull_request: + branches: + - main + +jobs: + uptime: + name: Uptime + runs-on: ubuntu-latest + steps: + - name: Checkout Code + uses: actions/checkout@v6 + + - name: Set Environment + id: vars + run: | + echo "tag=${GITHUB_REF#refs/*/}" >> $GITHUB_OUTPUT + echo "revision=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT + echo "build_date=$(date -u +%Y-%m-%d)" >> $GITHUB_OUTPUT + + - name: Docker Metadata + id: meta + uses: docker/metadata-action@v6 + with: + # list of Docker images to use as basenames for tags + # this should be configured for each container built + images: | + rotationalio/uptime + gcr.io/rotationalio-habanero/uptime + tags: | + type=semver,pattern={{raw}} + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + type=sha,prefix=,suffix=,format=short + + - name: Setup QEMU + uses: docker/setup-qemu-action@v4 + + - name: Setup Docker Buildx + id: buildx + uses: docker/setup-buildx-action@v4 + + - name: Login to DockerHub + if: github.event_name != 'pull_request' + uses: docker/login-action@v4 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_ACCESS_TOKEN }} + + - name: Login to GCR + if: github.event_name != 'pull_request' + uses: docker/login-action@v4 + with: + registry: gcr.io + username: _json_key + password: ${{ secrets.GCR_SERVICE_ACCOUNT }} + + - name: Build and push + id: docker_build + uses: docker/build-push-action@v7 + with: + context: . + file: ./Dockerfile + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + platforms: linux/amd64,linux/arm64 + build-args: | + GIT_REVISION=${{ steps.vars.outputs.revision }} + BUILD_DATE=${{ steps.vars.outputs.build_date }} diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..976bdff --- /dev/null +++ b/Dockerfile @@ -0,0 +1,50 @@ +# Dynamic builds +ARG BUILDER_IMAGE=dhi.io/golang:1.26-debian13-dev +ARG FINAL_IMAGE=dhi.io/golang:1.26-debian13 + +# Build stage +FROM --platform=${BUILDPLATFORM} ${BUILDER_IMAGE} AS builder + +# Build args +ARG GIT_REVISION="" +ARG BUILD_DATE="" + +# Platform args +ARG TARGETOS +ARG TARGETARCH +ARG TARGETPLATFORM + +# Use modules for dependencies +WORKDIR $GOPATH/src/go.rtnl.ai/uptime + +COPY go.mod . +COPY go.sum . + +# Set the build environment +ENV CGO_ENABLED=0 +ENV GO111MODULE=on +ENV GOOS=${TARGETOS} +ENV GOARCH=${TARGETARCH} + +# Install dependencies +RUN go mod download && go mod verify + +# Copy the source code +COPY pkg/ pkg/ +COPY cmd/ cmd/ + +# Build the uptime binary +RUN go build -o /go/bin/uptime \ + -ldflags="-X 'go.rtnl.ai/uptime/pkg.GitVersion=${GIT_REVISION}' -X 'go.rtnl.ai/uptime/pkg.BuildDate=${BUILD_DATE}'" \ + ./cmd/uptime + +# Final stage +FROM ${FINAL_IMAGE} AS final + +LABEL maintainer="Rotational Labs, Inc. " +LABEL description="Service status monitor for Rotational applications and systems." + +# Copy the uptime binary +COPY --from=builder /go/bin/uptime /usr/local/bin/uptime + +CMD [ "/usr/local/bin/uptime", "serve" ]