Skip to content

Commit

Permalink
Merge pull request #56 from k4my4b/new_oci_base
Browse files Browse the repository at this point in the history
New oci base
  • Loading branch information
k4my4b authored Sep 24, 2024
2 parents 1842d2e + 1f000c9 commit 1cd648d
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 0 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/base_build_and_publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Build and publish docker-cloud/base OCI package(s)

on:
push:
branches: [ "main" ]
paths: ["base/**"]

jobs:
build_and_publish:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
attestations: write
id-token: write
steps:
- uses: actions/checkout@v4
- name: Build and push the OCI base image to ghcr.io
run: |
docker login --username ${{ github.actor }} --password ${{ secrets.GITHUB_TOKEN }} ghcr.io
docker build ./base --tag ghcr.io/${{ github.actor }}/base:latest
docker push ghcr.io/${{ github.actor }}/base:latest
13 changes: 13 additions & 0 deletions base/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM alpine:3.19

RUN apk add --no-cache parallel grml-zsh-config

COPY --chmod=775 init.d /init.d
COPY --chmod=755 init.sh /init.sh
COPY --chmod=775 healthcheck.d /healthcheck.d
COPY --chmod=755 healthcheck.sh /healthcheck.sh

ENTRYPOINT ["/init.sh"]
CMD ["/init.d/start", "/init.d/stop"]

HEALTHCHECK CMD ["/healthcheck.sh", "/healthcheck.d"]
11 changes: 11 additions & 0 deletions base/healthcheck.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env sh

# Default healthcheck directory is /healthcheck.d if not passed as an argument
DIR="${1:-/healthcheck.d}"

# Find executable files in the healthcheck directory and run them in parallel
find "$DIR" -type f -executable | parallel --will-cite --halt 2 'sh {}' || {
echo "Container is unhealthy!"
kill -TERM 1
exit 1
}
3 changes: 3 additions & 0 deletions base/init.d/start/00-default.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env sh

echo "Starting up, hello!"
4 changes: 4 additions & 0 deletions base/init.d/stop/99-default.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh

echo "Shutting down, goodbye!"
exit 0
40 changes: 40 additions & 0 deletions base/init.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/usr/bin/env sh

# Default starting directory is /init.d/start if not passed as argument
INDIR="${1:-/init.d/start}"

# Default stoppping directory is /init.d/stop if not passed as argument
EDIR="${2:-/init.d/stop}"

batch_and_run_in_parallel() {
# Find and sort scripts
find "$1" -type f -executable -name '[0-9]*' | sort -V | \
# Group the scripts of the same priority together
awk '
{
split($0, arr, "/")
file = arr[length(arr)]
num = substr(file, 1, index(file, "-") - 1)
if (num != prev) {
if (NR > 1) {
print ""
}
prev = num
}
printf "%s ", $0
}
END { print "" }
' | \
# Execute scripts of the same priority (same group) in parallel
# Exit as soon as a script fails to execute properly
while IFS= read -r scripts; do
parallel --will-cite --halt 2 -k -u -d ' ' sh {} ::: $scripts || {
kill -TERM 1
exit 1
}
done
}

trap 'batch_and_run_in_parallel "$EDIR"' TERM EXIT

batch_and_run_in_parallel "$INDIR"

0 comments on commit 1cd648d

Please sign in to comment.