Skip to content

Commit

Permalink
Merge pull request #16 from Yolean/pre-push-hacks
Browse files Browse the repository at this point in the history
WIP pre-push-hacks
  • Loading branch information
solsson authored May 24, 2024
2 parents 9610163 + 49f23f3 commit 919020c
Show file tree
Hide file tree
Showing 14 changed files with 214 additions and 100 deletions.
22 changes: 21 additions & 1 deletion .github/workflows/images.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

# generated by ./test.sh for manual copy-paste to images.yaml
### build steps below are generated ###
-
name: Build and push builder-base latest
uses: docker/build-push-action@v5
Expand Down Expand Up @@ -238,6 +238,8 @@ jobs:
push: true
cache-from: type=gha
cache-to: type=gha,mode=max
build-contexts: |
yolean/java:root=docker-image://ghcr.io/yolean/java:root
-
name: Build and push node root
uses: docker/build-push-action@v5
Expand Down Expand Up @@ -266,6 +268,8 @@ jobs:
push: true
cache-from: type=gha
cache-to: type=gha,mode=max
build-contexts: |
yolean/node:root=docker-image://ghcr.io/yolean/node:root
-
name: Build and push node-kafka root
uses: docker/build-push-action@v5
Expand Down Expand Up @@ -296,6 +300,8 @@ jobs:
push: true
cache-from: type=gha
cache-to: type=gha,mode=max
build-contexts: |
yolean/node-kafka:root=docker-image://ghcr.io/yolean/node-kafka:root
-
name: Build and push node-kafka-cache root
uses: docker/build-push-action@v5
Expand Down Expand Up @@ -326,6 +332,8 @@ jobs:
push: true
cache-from: type=gha
cache-to: type=gha,mode=max
build-contexts: |
yolean/node-kafka-cache:root=docker-image://ghcr.io/yolean/node-kafka-cache:root
-
name: Build and push node-watchexec root
uses: docker/build-push-action@v5
Expand Down Expand Up @@ -354,6 +362,8 @@ jobs:
push: true
cache-from: type=gha
cache-to: type=gha,mode=max
build-contexts: |
yolean/node-watchexec:root=docker-image://ghcr.io/yolean/node-watchexec:root
-
name: Build and push node-gcloud root
uses: docker/build-push-action@v5
Expand Down Expand Up @@ -384,6 +394,8 @@ jobs:
push: true
cache-from: type=gha
cache-to: type=gha,mode=max
build-contexts: |
yolean/node-gcloud:root=docker-image://ghcr.io/yolean/node-gcloud:root
-
name: Build and push runtime-quarkus-ubuntu root
uses: docker/build-push-action@v5
Expand Down Expand Up @@ -412,6 +424,8 @@ jobs:
push: true
cache-from: type=gha
cache-to: type=gha,mode=max
build-contexts: |
yolean/runtime-quarkus-ubuntu:root=docker-image://ghcr.io/yolean/runtime-quarkus-ubuntu:root
-
name: Build and push runtime-quarkus-ubuntu-jre root
uses: docker/build-push-action@v5
Expand Down Expand Up @@ -443,6 +457,8 @@ jobs:
push: true
cache-from: type=gha
cache-to: type=gha,mode=max
build-contexts: |
yolean/runtime-quarkus-ubuntu-jre:root=docker-image://ghcr.io/yolean/runtime-quarkus-ubuntu-jre:root
-
name: Build and push runtime-quarkus-dev root
uses: docker/build-push-action@v5
Expand Down Expand Up @@ -474,6 +490,8 @@ jobs:
push: true
cache-from: type=gha
cache-to: type=gha,mode=max
build-contexts: |
yolean/runtime-quarkus-dev:root=docker-image://ghcr.io/yolean/runtime-quarkus-dev:root
-
name: Build and push toil-storage root
uses: docker/build-push-action@v5
Expand Down Expand Up @@ -505,3 +523,5 @@ jobs:
push: true
cache-from: type=gha
cache-to: type=gha,mode=max
build-contexts: |
yolean/toil-storage:root=docker-image://ghcr.io/yolean/toil-storage:root
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
**/node_modules/
actions-generated.yaml
99 changes: 0 additions & 99 deletions hooks/build

This file was deleted.

112 changes: 112 additions & 0 deletions test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
#!/usr/bin/env bash
[ -z "$DEBUG" ] || set -x
set -eo pipefail

[ -n "$PLATFORMS" ] || PLATFORMS="linux/amd64,linux/arm64/v8"
[ -n "$PLATFORM" ] || PLATFORM="--platform=$PLATFORMS"

[ -z "$REGISTRY" ] || PREFIX="$REGISTRY/"

SOURCE_COMMIT=$(git rev-parse --verify HEAD 2>/dev/null || echo '')
if [[ ! -z "$SOURCE_COMMIT" ]]; then
GIT_STATUS=$(git status --untracked-files=normal --porcelain=v2 | grep -v ' hooks/build' || true)
if [[ ! -z "$GIT_STATUS" ]]; then
SOURCE_COMMIT="$SOURCE_COMMIT-dirty"
fi
fi

MULTIARCH_NONROOT="
builder-base
builder-base-gcc
builder-base-gcloud
builder-tooling
builder-node
builder-quarkus
git-init
toil
toil-network
node-distroless
blobs
"

MULTIARCH_TONONROOT="
java
node
node-kafka
node-kafka-cache
node-watchexec
node-gcloud
runtime-quarkus-ubuntu
runtime-quarkus-ubuntu-jre
runtime-quarkus-dev
toil-storage
"

AMD64ONLY="
runtime-quarkus
runtime-quarkus-deno
runtime-deno
git-http-readonly
headless-chrome
"

BEGIN=" ### build steps below are generated ###"
CURRENT=.github/workflows/images.yaml
ACTIONS=$(mktemp)
sed "/^$BEGIN\$/q" $CURRENT > $ACTIONS

function base_action {
local CONTEXT=$1
local NAME=$2
local TAG=$3
local TAGSUFFIX=""
[ "$TAG" = "latest" ] || local TAGSUFFIX="-$TAG"
cat <<EOF
-
name: Build and push $NAME $TAG
uses: docker/build-push-action@v5
env:
SOURCE_DATE_EPOCH: 0
with:
context: $CONTEXT
tags: |
ghcr.io/yolean/$NAME:$TAG
ghcr.io/yolean/$NAME:\${{ github.sha }}$TAGSUFFIX
platforms: linux/amd64,linux/arm64/v8
push: true
cache-from: type=gha
cache-to: type=gha,mode=max
EOF
}

function add_dependencies {
local CONTEXT=$1
local DEPENDENCIES="$((grep -e 'FROM --platform=$TARGETPLATFORM yolean/' $CONTEXT/Dockerfile || true) | cut -d' ' -f3)"
[ -z "$DEPENDENCIES" ] || echo " build-contexts: |"
for NAME in $DEPENDENCIES; do
echo " $NAME=docker-image://ghcr.io/$NAME"
done
}
for CONTEXT in $MULTIARCH_NONROOT; do
base_action "$CONTEXT" "$CONTEXT" latest >> $ACTIONS
add_dependencies "$CONTEXT" >> $ACTIONS
done
for CONTEXT in $MULTIARCH_TONONROOT; do
mkdir -p to-nonroot/$CONTEXT
echo "FROM --platform=\$TARGETPLATFORM yolean/$CONTEXT:root" > to-nonroot/$CONTEXT/Dockerfile
cat nonroot-footer.Dockerfile >> to-nonroot/$CONTEXT/Dockerfile
base_action "$CONTEXT" "$CONTEXT" root >> $ACTIONS
add_dependencies "$CONTEXT" >> $ACTIONS
base_action "to-nonroot/$CONTEXT" "$CONTEXT" latest >> $ACTIONS
add_dependencies "to-nonroot/$CONTEXT" >> $ACTIONS
done
for CONTEXT in $AMD64ONLY; do
echo "# TODO does $CONTEXT really need to be amd64-only?" >&2
done
cp $ACTIONS $CURRENT
GIT_STATUS=$(git status --untracked-files=no --porcelain=v2)
[ -z "$GIT_STATUS" ] && echo "Done, no local diff" || echo "Done, with local diff"
8 changes: 8 additions & 0 deletions to-nonroot/java/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM --platform=$TARGETPLATFORM yolean/java:root

# Appends the same nonroot directives as https://github.com/Yolean/kubernetes-kafka/tree/master/nonroot
# i.e. https://github.com/solsson/dockerfiles/tree/native/kafka-nonroot
RUN grep 'nonroot:x:65532' /etc/passwd || \
echo 'nonroot:x:65532:65534:nonroot:/home/nonroot:/usr/sbin/nologin' >> /etc/passwd && \
mkdir -p /home/nonroot && touch /home/nonroot/.bash_history && chown -R 65532:65534 /home/nonroot
USER nonroot:nogroup
8 changes: 8 additions & 0 deletions to-nonroot/node-gcloud/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM --platform=$TARGETPLATFORM yolean/node-gcloud:root

# Appends the same nonroot directives as https://github.com/Yolean/kubernetes-kafka/tree/master/nonroot
# i.e. https://github.com/solsson/dockerfiles/tree/native/kafka-nonroot
RUN grep 'nonroot:x:65532' /etc/passwd || \
echo 'nonroot:x:65532:65534:nonroot:/home/nonroot:/usr/sbin/nologin' >> /etc/passwd && \
mkdir -p /home/nonroot && touch /home/nonroot/.bash_history && chown -R 65532:65534 /home/nonroot
USER nonroot:nogroup
8 changes: 8 additions & 0 deletions to-nonroot/node-kafka-cache/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM --platform=$TARGETPLATFORM yolean/node-kafka-cache:root

# Appends the same nonroot directives as https://github.com/Yolean/kubernetes-kafka/tree/master/nonroot
# i.e. https://github.com/solsson/dockerfiles/tree/native/kafka-nonroot
RUN grep 'nonroot:x:65532' /etc/passwd || \
echo 'nonroot:x:65532:65534:nonroot:/home/nonroot:/usr/sbin/nologin' >> /etc/passwd && \
mkdir -p /home/nonroot && touch /home/nonroot/.bash_history && chown -R 65532:65534 /home/nonroot
USER nonroot:nogroup
8 changes: 8 additions & 0 deletions to-nonroot/node-kafka/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM --platform=$TARGETPLATFORM yolean/node-kafka:root

# Appends the same nonroot directives as https://github.com/Yolean/kubernetes-kafka/tree/master/nonroot
# i.e. https://github.com/solsson/dockerfiles/tree/native/kafka-nonroot
RUN grep 'nonroot:x:65532' /etc/passwd || \
echo 'nonroot:x:65532:65534:nonroot:/home/nonroot:/usr/sbin/nologin' >> /etc/passwd && \
mkdir -p /home/nonroot && touch /home/nonroot/.bash_history && chown -R 65532:65534 /home/nonroot
USER nonroot:nogroup
8 changes: 8 additions & 0 deletions to-nonroot/node-watchexec/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM --platform=$TARGETPLATFORM yolean/node-watchexec:root

# Appends the same nonroot directives as https://github.com/Yolean/kubernetes-kafka/tree/master/nonroot
# i.e. https://github.com/solsson/dockerfiles/tree/native/kafka-nonroot
RUN grep 'nonroot:x:65532' /etc/passwd || \
echo 'nonroot:x:65532:65534:nonroot:/home/nonroot:/usr/sbin/nologin' >> /etc/passwd && \
mkdir -p /home/nonroot && touch /home/nonroot/.bash_history && chown -R 65532:65534 /home/nonroot
USER nonroot:nogroup
8 changes: 8 additions & 0 deletions to-nonroot/node/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM --platform=$TARGETPLATFORM yolean/node:root

# Appends the same nonroot directives as https://github.com/Yolean/kubernetes-kafka/tree/master/nonroot
# i.e. https://github.com/solsson/dockerfiles/tree/native/kafka-nonroot
RUN grep 'nonroot:x:65532' /etc/passwd || \
echo 'nonroot:x:65532:65534:nonroot:/home/nonroot:/usr/sbin/nologin' >> /etc/passwd && \
mkdir -p /home/nonroot && touch /home/nonroot/.bash_history && chown -R 65532:65534 /home/nonroot
USER nonroot:nogroup
8 changes: 8 additions & 0 deletions to-nonroot/runtime-quarkus-dev/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM --platform=$TARGETPLATFORM yolean/runtime-quarkus-dev:root

# Appends the same nonroot directives as https://github.com/Yolean/kubernetes-kafka/tree/master/nonroot
# i.e. https://github.com/solsson/dockerfiles/tree/native/kafka-nonroot
RUN grep 'nonroot:x:65532' /etc/passwd || \
echo 'nonroot:x:65532:65534:nonroot:/home/nonroot:/usr/sbin/nologin' >> /etc/passwd && \
mkdir -p /home/nonroot && touch /home/nonroot/.bash_history && chown -R 65532:65534 /home/nonroot
USER nonroot:nogroup
8 changes: 8 additions & 0 deletions to-nonroot/runtime-quarkus-ubuntu-jre/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM --platform=$TARGETPLATFORM yolean/runtime-quarkus-ubuntu-jre:root

# Appends the same nonroot directives as https://github.com/Yolean/kubernetes-kafka/tree/master/nonroot
# i.e. https://github.com/solsson/dockerfiles/tree/native/kafka-nonroot
RUN grep 'nonroot:x:65532' /etc/passwd || \
echo 'nonroot:x:65532:65534:nonroot:/home/nonroot:/usr/sbin/nologin' >> /etc/passwd && \
mkdir -p /home/nonroot && touch /home/nonroot/.bash_history && chown -R 65532:65534 /home/nonroot
USER nonroot:nogroup
8 changes: 8 additions & 0 deletions to-nonroot/runtime-quarkus-ubuntu/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM --platform=$TARGETPLATFORM yolean/runtime-quarkus-ubuntu:root

# Appends the same nonroot directives as https://github.com/Yolean/kubernetes-kafka/tree/master/nonroot
# i.e. https://github.com/solsson/dockerfiles/tree/native/kafka-nonroot
RUN grep 'nonroot:x:65532' /etc/passwd || \
echo 'nonroot:x:65532:65534:nonroot:/home/nonroot:/usr/sbin/nologin' >> /etc/passwd && \
mkdir -p /home/nonroot && touch /home/nonroot/.bash_history && chown -R 65532:65534 /home/nonroot
USER nonroot:nogroup
Loading

0 comments on commit 919020c

Please sign in to comment.