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
11 changes: 11 additions & 0 deletions .github/workflows/build-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ jobs:
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0

# Install the cosign tool except on PR
# https://github.com/sigstore/cosign-installer
Expand Down Expand Up @@ -74,6 +76,12 @@ jobs:
type=semver,pattern={{major}}
type=raw,value=latest,enable={{is_default_branch}}

- name: Set build time
run: echo "BUILDTIME=$(date -u +%Y-%m-%dT%H:%M:%SZ)" >> $GITHUB_ENV

- name: Set build VERSION
run: echo "VERSION=$(git describe --tags --abbrev)" >> $GITHUB_ENV

# Build and push Docker image with Buildx (don't push on PR)
# https://github.com/docker/build-push-action
- name: Build and push Docker image
Expand All @@ -85,6 +93,9 @@ jobs:
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
no-cache: true
build-args: |
BUILDTIME=${{ env.BUILDTIME }}
VERSION=${{ env.VERSION }}

# Sign the resulting Docker image digest except on PRs.
# This will only write to the public Rekor transparency log when the Docker
Expand Down
22 changes: 12 additions & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
FROM golang:latest AS builder

ARG BRANCH=${BRANCH:-main}
ARG OSVC_GITREPO_URL=${OSVC_GITREPO_URL:-https://github.com/opensvc/oc3.git}

WORKDIR /opt

RUN git clone $OSVC_GITREPO_URL && echo "Cache busted at $(date): git clone $OSVC_GITREPO_URL"
ARG BUILDTIME
ARG VERSION

WORKDIR /opt/oc3
COPY . .

RUN git checkout $BRANCH && echo "Cache busted at $(date): git checkout $BRANCH"
RUN echo "VERSION=${VERSION}"

RUN git describe --tags --abbrev > util/version/text/VERSION
RUN echo "BUILDTIME=${BUILDTIME}"

RUN echo "${VERSION}" > util/version/text/VERSION

RUN CGO_ENABLED=0 go build -ldflags="-s -w" -o dist/oc3 .

RUN dist/oc3 version

RUN echo "Cache busted at $(date): oc3 version: $(./dist/oc3 version)"

FROM alpine:3.20.1
FROM alpine:3.22.4
ARG BUILDTIME

RUN apk add --no-cache bash git
RUN apk add --no-cache bash

COPY --from=builder /opt/oc3/dist/oc3 /usr/bin/oc3

Expand Down
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,11 @@ worker.fast:
- "node_disk"
- "object_config"
- "system"
```
```

## manual build docker image

docker build \
--build-arg BUILDTIME="$(date -u +%Y-%m-%dT%H:%M:%SZ)" \
--build-arg VERSION="$(git describe --tags --abbrev)" \
-t opensvc/oc3 .
Loading