-
Notifications
You must be signed in to change notification settings - Fork 59
Build and publish container images #151
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
Open
mbaum0
wants to merge
26
commits into
balzack:main
Choose a base branch
from
mbaum0:publish-container-image
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
42c1ab4
build and push docker images to ghcr
mbaum0 33898c7
use JSON args for dockerfile
mbaum0 d0ae80a
build image in ci workflow
mbaum0 718f05e
run on this branch
mbaum0 c7d8cbd
publish image workflow
mbaum0 dbd741c
run yarn install
mbaum0 a93c07f
upgrade yarn lock file
mbaum0 166555c
revert yarn.lock
mbaum0 d4f8491
push in ci
mbaum0 22be170
remove arm64
mbaum0 434d6b7
remove from ci
mbaum0 fd32795
fix comment
mbaum0 34f1869
release please
mbaum0 9ce03ad
revert
mbaum0 cfbb0f9
publish release
mbaum0 eebe14d
fix workflow
mbaum0 1542735
fix tags
mbaum0 a58d7b6
remove release bit
mbaum0 9f2f35e
add newline to yarn.lock
mbaum0 9ad59b4
revert changes to ci job
mbaum0 81db04e
build container for arm64
mbaum0 040ad6e
fix typo
mbaum0 ef0bb32
trigger on test branch
mbaum0 cfcc5e8
fix yarn cache
mbaum0 8815a30
test and stable images
mbaum0 4c172d9
only run stable image build on version tags
mbaum0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
name: Build and Push Release Image | ||
|
||
# Configures this workflow to run for every new version tag | ||
on: | ||
push: | ||
tags: ["v*.*.*"] | ||
|
||
env: | ||
REGISTRY: ghcr.io | ||
IMAGE_NAME: ${{ github.repository }} | ||
|
||
jobs: | ||
build-and-push-image: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: read | ||
packages: write | ||
attestations: write | ||
id-token: write | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
|
||
# Log into GHCR | ||
- name: Log in to the Container registry | ||
uses: docker/login-action@v3 | ||
with: | ||
registry: ${{ env.REGISTRY }} | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
# Extract version from tag name | ||
# example: tag name `v1.0.0` sets env.VERSION=1.0.0 | ||
- name: Extract build args | ||
run: | | ||
echo "VERSION=${GITHUB_REF_NAME#v}" >> $GITHUB_ENV | ||
|
||
# Set up QEMU for cross-compiling | ||
- name: Set up QEMU | ||
uses: docker/setup-qemu-action@v3 | ||
|
||
# Set up docker-buildx for cross-compiling | ||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v3 | ||
|
||
- name: Docker meta | ||
id: meta | ||
uses: docker/metadata-action@v5 | ||
with: | ||
images: | | ||
balzack/databag | ||
ghcr.io/balzack/databag | ||
tags: | | ||
type=semver,pattern={{version}},value=${{ env.VERSION }} | ||
type=semver,pattern={{major}}.{{minor}},value=${{ env.VERSION }} | ||
type=raw,value=stable | ||
flavor: | | ||
latest=false | ||
labels: | | ||
org.opencontainers.image.version=${{ env.VERSION }} | ||
|
||
# Build and push container image with associated labels and tags. | ||
- name: Build and push Docker image | ||
id: push | ||
uses: docker/build-push-action@v6 | ||
with: | ||
context: . | ||
platforms: linux/amd64,linux/arm64 | ||
push: true | ||
tags: ${{ steps.meta.outputs.tags }} | ||
labels: ${{ steps.meta.outputs.labels }} | ||
|
||
# Generate attestation | ||
- name: Generate artifact attestation | ||
uses: actions/attest-build-provenance@v2 | ||
with: | ||
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}} | ||
subject-digest: ${{ steps.push.outputs.digest }} | ||
push-to-registry: true |
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,69 @@ | ||
name: Build and Push Test Image | ||
|
||
# Configures this workflow to run for every PR | ||
on: | ||
pull_request: | ||
branches: ["main"] | ||
|
||
env: | ||
REGISTRY: ghcr.io | ||
IMAGE_NAME: ${{ github.repository }} | ||
|
||
jobs: | ||
build-and-push-image: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: read | ||
packages: write | ||
attestations: write | ||
id-token: write | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
|
||
# Log into GHCR | ||
- name: Log in to the Container registry | ||
uses: docker/login-action@v3 | ||
with: | ||
registry: ${{ env.REGISTRY }} | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
# Set up QEMU for cross-compiling | ||
- name: Set up QEMU | ||
uses: docker/setup-qemu-action@v3 | ||
|
||
# Set up docker-buildx for cross-compiling | ||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v3 | ||
|
||
- name: Docker meta | ||
id: meta | ||
uses: docker/metadata-action@v5 | ||
with: | ||
images: | | ||
balzack/databag | ||
ghcr.io/balzack/databag | ||
tags: | | ||
type=raw,value=test | ||
flavor: | | ||
latest=false | ||
|
||
# Build and push container image with associated labels and tags. | ||
- name: Build and push Docker image | ||
id: push | ||
uses: docker/build-push-action@v6 | ||
with: | ||
context: . | ||
platforms: linux/amd64,linux/arm64 | ||
push: true | ||
tags: ${{ steps.meta.outputs.tags }} | ||
labels: ${{ steps.meta.outputs.labels }} | ||
|
||
# Generate attestation | ||
- name: Generate artifact attestation | ||
uses: actions/attest-build-provenance@v2 | ||
with: | ||
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}} | ||
subject-digest: ${{ steps.push.outputs.digest }} | ||
push-to-registry: true |
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 |
---|---|---|
|
@@ -2,12 +2,16 @@ FROM node:22-alpine AS node | |
WORKDIR /app | ||
|
||
# Download the node dependencies first before adding the rest for caching | ||
# target=/usr/local/share/.cache/yarn/v6 is the default cache directory for yarn. | ||
# This can be obtained via `docker run -it node:22-alpine yarn cache dir` | ||
# sharing=locked: this will force docker to wait for each parallel build in sequence. | ||
# This prevents multi-architecture builds from running over each otther. | ||
COPY ./net/web/package.json ./net/web/yarn.lock ./ | ||
RUN --mount=type=cache,target=/root/.yarn YARN_CACHE_FOLDER=/root/.yarn \ | ||
RUN --mount=type=cache,target=/usr/local/share/.cache/yarn/v6,sharing=locked \ | ||
yarn --frozen-lockfile | ||
|
||
COPY ./net/web/ ./ | ||
RUN --mount=type=cache,target=/root/.yarn YARN_CACHE_FOLDER=/root/.yarn \ | ||
RUN --mount=type=cache,target=/usr/local/share/.cache/yarn/v6,sharing=locked \ | ||
yarn run build | ||
|
||
FROM golang:alpine AS go | ||
|
@@ -24,22 +28,16 @@ COPY ./net/server /app/databag/net/server | |
COPY ./net/transform /opt/databag/transform | ||
|
||
WORKDIR /app/databag/net/server | ||
RUN --mount=type=cache,target=/go/pkg/mod \ | ||
if [ -n "${DATABAG_GOARCH}" ]; then GOARCH=${DATABAG_GOARCH}; fi; \ | ||
if [ -n "${DATABAG_GOOS}" ]; then GOOS=${DATABAG_GOOS}; fi; \ | ||
go mod download | ||
RUN --mount=type=cache,target=/go/pkg/mod go mod download | ||
|
||
ARG DATABAG_GOARCH | ||
ARG DATABAG_GOOS | ||
Comment on lines
+31
to
34
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't the args be placed first or doesn't that matter? |
||
|
||
RUN --mount=type=cache,target=/go/pkg/mod \ | ||
if [ -n "${DATABAG_GOARCH}" ]; then GOARCH=${DATABAG_GOARCH}; fi; \ | ||
if [ -n "${DATABAG_GOOS}" ]; then GOOS=${DATABAG_GOOS}; fi; \ | ||
CGO_ENABLED=1 go build -o databag . | ||
RUN --mount=type=cache,target=/go/pkg/mod CGO_ENABLED=1 go build -o databag . | ||
|
||
COPY --from=node /app/build /app/databag/net/web/build | ||
|
||
ENV DEV=0 | ||
ENV ADMIN=password | ||
|
||
ENTRYPOINT /app/databag/net/server/entrypoint.sh | ||
ENTRYPOINT ["/app/databag/net/server/entrypoint.sh"] |
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 |
---|---|---|
|
@@ -3,14 +3,6 @@ name: databag | |
services: | ||
app: | ||
build: . | ||
|
||
# # For building cross environment containers | ||
# build: | ||
# context: . | ||
# args: | ||
# DATABAG_GOARCH: arm64 | ||
# DATABAG_GOOS: linux | ||
# platform: "linux/arm64" | ||
Comment on lines
-6
to
-13
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why remove this? |
||
ports: | ||
- 127.0.0.1:7000:7000 | ||
volumes: | ||
|
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
Oops, something went wrong.
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.
using sharing=locked could be an issue if 2 PRs are created at once