Skip to content

Commit

Permalink
build(image): refacor build process
Browse files Browse the repository at this point in the history
Signed-off-by: Nico Braun <[email protected]>
  • Loading branch information
bluebrown committed Jan 21, 2024
1 parent f5b23cc commit 208c131
Show file tree
Hide file tree
Showing 11 changed files with 52 additions and 10 deletions.
3 changes: 3 additions & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#!/usr/bin/env bash

dotenv .env
dotenv_if_exists .local/.env

PATH_add .local/bin

export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$PWD/.local/lib"
2 changes: 1 addition & 1 deletion .github/workflows/image.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
- uses: actions/checkout@v3
- run: |
docker login --username bluebrown --password ${{secrets.DOCKERHUB_TOKEN}}
docker build -t "docker.io/bluebrown/kobold:$(git describe --tags --always --dirty)" -f build/Dockerfile .
bash build/image.sh
docker push docker.io/bluebrown/kobold --all-tags
env:
DOCKER_BUILDKIT: "1"
2 changes: 0 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
.PHONY: install check lint test vet generate testinfra dev
bin=.local/bin

export RELEASE_TAG ?= $(shell git describe --tags --always --dirty)

artifacts:
bash build/artifacts.sh

Expand Down
1 change: 1 addition & 0 deletions build/.sqliterc
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.load uuid
.load sha1
.mode json
12 changes: 11 additions & 1 deletion build/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ ADD https://www.sqlite.org/src/raw/5bb2264c1b64d163efa46509544fd7500cb8769cb7c16
RUN gcc -shared -fPIC -o /usr/local/lib/uuid.so uuid.c

FROM base as runtime
RUN apk add --no-cache --update ca-certificates git openssh-client
RUN apk add --no-cache --update ca-certificates git openssh-client jq
COPY --from=sqlite /usr/local/bin /usr/local/bin
COPY --from=sqlite /usr/local/lib /usr/local/lib
RUN ldconfig /usr/local/lib
Expand Down Expand Up @@ -52,3 +52,13 @@ ENV GIT_AUTHOR_NAME="kobold[bot]" \
GIT_AUTHOR_EMAIL="[email protected]"
ENV GIT_COMMITTER_NAME="$GIT_AUTHOR_NAME" \
GIT_COMMITTER_EMAIL="$GIT_AUTHOR_EMAIL"
LABEL org.opencontainers.image.title="kobold" \
org.opencontainers.image.description="Image reference update bot" \
org.opencontainers.image.authors="Nico Braun" \
org.opencontainers.image.vendor="bluebrown" \
org.opencontainers.image.licenses="BSD-3-Clause" \
org.opencontainers.image.url="https://hub.docker.com/r/bluebrown/kobold" \
org.opencontainers.image.source="https://github.com/bluebrown/kobold"
ARG BUILD_DATE="unknown" VCS_REF="unknown"
LABEL org.opencontainers.image.created="$BUILD_DATE" \
org.opencontainers.image.revision="$VCS_REF"
13 changes: 10 additions & 3 deletions build/artifacts.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#!/usr/bin/env bash
set -o nounset -o errexit -o errtrace -o pipefail

tag="$(sh build/gettag.sh)"

out="${1:-.artifacts}"
out="${out%/}"
tag="${RELEASE_TAG:-dev}"

echo "Building artifacts in $out" >&2

Expand All @@ -23,13 +24,19 @@ kustomize create
kustomize edit add resource "../kube"
kustomize edit set image "docker.io/bluebrown/kobold:$tag"
kustomize edit set label app.kubernetes.io/name:kobold
kustomize edit set label "app.kubernetes.io/version:$tag"
cat <<EOF >>kustomization.yaml
labels:
- includeSelectors: false
pairs:
app.kubernetes.io/version: $tag
EOF
cd -
kustomize build "$td" >"$out/manifests.yaml"

echo "Building OCI image..." >&2

docker build -f build/Dockerfile -t "docker.io/bluebrown/kobold:$tag" .
bash build/image.sh

docker save "docker.io/bluebrown/kobold:$tag" >"$out/oci.tar"

echo "Building binaries..." >&2
Expand Down
2 changes: 1 addition & 1 deletion build/compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ services:
context: ../
dockerfile: build/Dockerfile
ports:
- 127.0.0.1:8081:8080
- 127.0.0.1:8080:8080
volumes:
- ../testdata/kobold.toml:/etc/kobold/kobold.toml:ro
- ../.local/.ssh:/etc/kobold/.ssh:rw
Expand Down
7 changes: 7 additions & 0 deletions build/gettag.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env sh

if [ -n "$RELEASE_TAG" ]; then
echo "$RELEASE_TAG"
else
git describe --tags --always --dirty
fi
13 changes: 13 additions & 0 deletions build/image.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env bash
set -o nounset -o errexit -o errtrace -o pipefail

script_dir="$(dirname "$(readlink -f "$0")")"
cd "$script_dir/.."

tag="$(sh build/gettag.sh)"
vcs_ref="$(git rev-parse --short HEAD)"

docker build -t "docker.io/bluebrown/kobold:$tag" \
--build-arg BUILD_DATE="$(date -u +'%Y-%m-%dT%H:%M:%SZ')" \
--build-arg VCS_REF="$vcs_ref" \
-f build/Dockerfile .
5 changes: 4 additions & 1 deletion git/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,10 @@ func (cache *RepoCache) Fill(ctx context.Context, lim int, uris ...PackageURI) e
if cache.cfetch != nil {
cache.cfetch.With(prometheus.Labels{"repo": uri}).Inc()
}
return Ensure(ctx, filepath.Join(cache.dir, "repos", uri), uri, refs...)
if err := Ensure(ctx, filepath.Join(cache.dir, "repos", uri), uri, refs...); err != nil {
return fmt.Errorf("ensure %q: %w", uri, err)
}
return nil
})
}

Expand Down
2 changes: 1 addition & 1 deletion testdata/events.http
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
POST /events?chan=dockerhub HTTP/1.1
Host: localhost:9000
Host: localhost:8080

{
"push_data": {
Expand Down

0 comments on commit 208c131

Please sign in to comment.