-
Notifications
You must be signed in to change notification settings - Fork 7
Switch to Docker-based builds and releases #57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| name: Build images and release if tagged | ||
| run-name: Build images ${{ startsWith(github.ref, 'refs/tags/v') && 'and release' || 'and publish preview image' }} | ||
|
|
||
| on: | ||
| pull_request: | ||
| # https://docs.github.com/en/actions/reference/workflows-and-actions/events-that-trigger-workflows#pull_request | ||
| # and https://docs.github.com/en/webhooks/webhook-events-and-payloads?actionType=synchronize#pull_request | ||
| # can probably combine with a caller to filter on label following | ||
| # https://stackoverflow.com/questions/62325286/run-github-actions-when-pull-requests-have-a-specific-label | ||
| # This saves on Actions costs for PRs that don't really need a preview image (anything that's just CI changes, smaller code changes, etc.) | ||
| # However, doing that sucht that subsequent build jobs can run still for main branch and tags (which have no labels ever) | ||
| # is kinda annoying condition-wise. We can maybe use a prelim step that has some simple "if PR event, if label: true, else: false || if other event: true" logic, | ||
| # require it for the build steps, and proceed only if it's successful? | ||
| types: [opened, synchronize] | ||
| push: | ||
| branches: | ||
| - 'main' | ||
| tags: | ||
| - 'v*' | ||
|
|
||
| permissions: write-all # Necessary for the generate-build-provenance action with containers | ||
|
|
||
| jobs: | ||
| image: | ||
| name: Build Image | ||
| uses: OpenCHAMI/github-actions/.github/workflows/go-build-release.yml@v3.3 | ||
| with: | ||
| fetch-depth: 1 | ||
| registry-name: ghcr.io/openchami/pcs | ||
| cgo-enabled: true | ||
| platforms: "linux/amd64" | ||
| docker-file: "Dockerfile.build" | ||
| image_arm: | ||
| name: Build ARM Image | ||
| uses: OpenCHAMI/github-actions/.github/workflows/go-build-release.yml@v3.3 | ||
| with: | ||
| fetch-depth: 1 | ||
| registry-name: ghcr.io/openchami/pcs | ||
| cgo-enabled: true | ||
| additional-env-vars: | | ||
| CC=aarch64-linux-gnu-gcc | ||
| platforms: "linux/arm64" | ||
| docker-file: "Dockerfile.build" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| ### builder | ||
| # Build the binary | ||
| # TODO this needs to match go.mod. Unsure how they can be | ||
| # kept in sync. | ||
| FROM --platform=$BUILDPLATFORM golang:1.24 AS builder | ||
|
|
||
| ARG GOPATH | ||
| ARG GOCACHE | ||
|
|
||
| ARG TARGETPLATFORM | ||
| ARG TARGETOS | ||
| ARG TARGETARCH | ||
|
|
||
| ARG CC | ||
|
|
||
| RUN printf "Building for TARGETPLATFORM=${TARGETPLATFORM}" \ | ||
| && printf ", TARGETARCH=${TARGETARCH}" \ | ||
| && printf ", TARGETOS=${TARGETOS}" \ | ||
| && printf ", TARGETVARIANT=${TARGETVARIANT} \n" \ | ||
| && printf "With 'uname -s': $(uname -s) and 'uname -m': $(uname -m)" | ||
|
|
||
| WORKDIR /workspace | ||
|
|
||
| # TODO | ||
| # We currently have a lot of variance in directory structure. | ||
| # This is annoying for Dockerfile design; we can't just consistently | ||
| # copy the same set of files. Enforcing pkg/ and internal/ only across | ||
| # the board would maybe help. | ||
| # Original also had this copying to GOPATH, e.g. | ||
| # COPY cmd $GOPATH/src/github.com/OpenCHAMI/power-control/v2/cmd | ||
| # I've encountered enough Dockerfiles that just copy it to workdir | ||
| COPY cmd cmd | ||
| COPY api api | ||
| COPY internal internal | ||
| COPY go.mod go.mod | ||
| COPY go.sum go.sum | ||
|
|
||
| # TODO | ||
| # These are more for the final image. Unsure if we need them for build. | ||
| # At worst they're just some extra dead weight, pruning them later is easy, and it's not like we really care about the size of the build image | ||
| COPY configs configs | ||
| COPY scripts scripts | ||
| COPY migrations migrations | ||
|
|
||
| # Build | ||
| ARG CGO_ENABLED | ||
|
|
||
| RUN mkdir bin | ||
|
|
||
| RUN CGO_ENABLED="${CGO_ENABLED}" GOOS=linux GOARCH="${TARGETARCH}" CC="${CC}" GO111MODULE=on go build -v -o bin/power-control ./cmd/power-control | ||
|
|
||
| ### release image | ||
| # TODO seems kinda off that we don't pin wolfi or tini, but whatever | ||
| FROM chainguard/wolfi-base:latest AS main | ||
|
|
||
| RUN set -ex \ | ||
| && apk update \ | ||
| && apk add --no-cache tini \ | ||
| && rm -rf /var/cache/apk/* \ | ||
| && rm -rf /tmp/* | ||
|
|
||
| WORKDIR / | ||
| COPY --from=builder /workspace/bin/power-control /usr/local/bin/ | ||
| COPY configs configs | ||
| COPY migrations migrations | ||
|
|
||
| #nobody 65534:65534 | ||
| USER 65534:65534 | ||
|
|
||
| CMD /usr/local/bin/power-control | ||
|
|
||
| ENTRYPOINT ["/sbin/tini", "--"] | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need another
Dockerfile?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To build a real tall stack of em. We've got so many, we may as well continue and build a Dockerfile staircase to the moon.This is another instance of existing stuff left in place pending full vet of the new system, to leave an easy revert path if I screwed up something major. Eventually, I expect to replace the existing
Dockerfilecontents with the contents ofDockerfile.build.I can possibly merge
Dockerfile.debuginto it as well, since it was separate for similar "doesn't work with the GoReleaser-style 'binary comes from a mystery black box prior todocker build' pipeline" reasons.The test ones will have to remain separate AFAIK.