Skip to content

Commit

Permalink
fix: script
Browse files Browse the repository at this point in the history
  • Loading branch information
kyubisation committed Jan 28, 2025
1 parent 45eba89 commit 2baddbb
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 66 deletions.
23 changes: 3 additions & 20 deletions .github/Dockerfile.regenerate
Original file line number Diff line number Diff line change
@@ -1,22 +1,5 @@
ARG BASE=ghcr.io/sbb-design-systems/sbb-angular/showcase:latest
FROM $BASE as base

# For version 11 + 12
FROM nginxinc/nginx-unprivileged:stable as initless

# Copy config from base image
COPY --from=base /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf
# Copy showcase from base image
COPY --from=base /usr/share/nginx/html /usr/share/nginx/html

# For versions 13+
FROM nginxinc/nginx-unprivileged:stable as init
FROM nginxinc/nginx-unprivileged:stable

# Copy config from base image
COPY --from=base /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf
# Copy showcase from base image
COPY --from=base /usr/share/nginx/html /usr/share/nginx/html
# Copy ngssc from base image if it exists
COPY --from=base /usr/sbin/ngssc /usr/sbin/ngssc
# Copy ngssc.sh from base image if it exists
COPY --from=base /docker-entrypoint.d/ngssc.sh /docker-entrypoint.d/ngssc.sh
COPY default.conf /etc/nginx/conf.d/default.conf
COPY html /usr/share/nginx/html
11 changes: 11 additions & 0 deletions .github/Dockerfile.regenerate.ngssc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# For versions 13+
FROM nginxinc/nginx-unprivileged:stable

COPY default.conf /etc/nginx/conf.d/default.conf
COPY html /usr/share/nginx/html
USER root
COPY ngssc /usr/sbin/ngssc
RUN chmod +x /usr/sbin/ngssc
COPY ngssc.sh /docker-entrypoint.d/ngssc.sh
RUN chmod +x /docker-entrypoint.d/ngssc.sh
USER $UID
6 changes: 2 additions & 4 deletions .github/actions/setup-mint/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,14 @@ runs:
steps:
- name: Setup mint
run: |
mkdir -p /tmp/mint
cd /tmp/mint
mkdir -p "$HOME/.local/bin"
cd "$HOME/.local/bin"
# Get the current released tag_name
VER=$(curl -sL https://api.github.com/repos/mintoolkit/mint/releases \
| grep tag_name | head -n1 | cut -d'"' -f4)
curl -L -o mint.tar.gz "https://github.com/mintoolkit/mint/releases/download/${VER}/dist_linux.tar.gz"
tar -xvf mint.tar.gz --strip-components 1
echo "/tmp/mint" >> $GITHUB_PATH
echo "Installed mint:${VER}"
shell: bash
64 changes: 22 additions & 42 deletions .github/workflows/regenerate-images.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,57 +9,37 @@ on:
permissions:
packages: write

env:
IMAGE_REPO: ghcr.io/${{ github.repository }}/showcase


jobs:
preview-image:
tag-resolver:
runs-on: ubuntu-latest
env:
START_VERSION: 11
IMAGE_REPO: ghcr.io/${{ github.repository }}/showcase
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
with:
fetch-depth: 0
fetch-tags: true
- uses: ./.github/actions/setup-mint
- name: Regenerate latest container images to keep them up to date
- name: Find latest tags from major versions
run: |
echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u $ --password-stdin
majorVersion=$START_VERSION
echo "Starting image regeneration with version $majorVersion"
while : ; do
version=$(git tag --sort=v:refname -l "$majorVersion.*.*" | tail -1)
[[ "$version" != "" ]] || break
image="$IMAGE_REPO:$version"
echo ""
echo "Regenerating $image"
echo ""
(( $majorVersion < 13 )) && target=initless || target=init
docker build \
--tag tmp-fat \
--build-arg BASE="$image" \
--file .github/Dockerfile.regenerate \
--target $target \
.
# Try/Catch
{
mint slim \
--target tmp-fat \
--tag tmp \
--preserve-path /usr/share/nginx/html
} || {
docker tag tmp-fat tmp
}
docker tag tmp "$image"
docker push "$image"
echo ""
echo "Finished regenerating $image"
echo ""
majorVersion=$((majorVersion+1))
done
./scripts/regenerate-image.sh >> "$GITHUB_OUTPUT"
env:
DOCKER_BUILDKIT: 1

regenerate-image:
runs-on: ubuntu-latest
needs: tag-resolver
strategy:
matrix:
version: ${{ fromJSON(needs.tag-resolver.outputs.versions) }}
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
- uses: ./.github/actions/setup-mint
- run: |
echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u $ --password-stdin
./scripts/regenerate-image.sh
env:
VERSION: ${{ matrix.version }}
19 changes: 19 additions & 0 deletions scripts/find-major-versions.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
set -e

if [ -z "${START_VERSION}" ]; then
echo "Missing START_VERSION variable"
exit 1
fi

majorVersion=$START_VERSION
versions=()

while : ; do
version=$(git tag --sort=v:refname -l "$majorVersion.*.*" | tail -1)
[[ "$version" != "" ]] || break
versions+=("$version")
majorVersion=$((majorVersion+1))
done

printf -v joined '"%s",' "${versions[@]}"
echo "versions=[${joined::-1}]"
47 changes: 47 additions & 0 deletions scripts/regenerate-image.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
set -e

if [ -z "${IMAGE_REPO}" ]; then
echo "Missing IMAGE_REPO variable"
exit 1
elif [ -z "${VERSION}" ]; then
echo "Missing VERSION variable"
exit 1
fi

image="$IMAGE_REPO:$VERSION"
majorVersion="${VERSION%.*.*}"
target=""
echo ""
echo "Regenerating $image"
echo ""

mkdir -p "$PWD/dist"

docker create --name dummy $image
if [[ $majorVersion > 12 ]]; then
target=".ngssc"
docker cp dummy:/usr/sbin/ngssc "$PWD/dist/ngssc"
docker cp dummy:/docker-entrypoint.d/ngssc.sh "$PWD/dist/ngssc.sh"
fi

docker cp dummy:/etc/nginx/conf.d/default.conf "$PWD/dist/default.conf"
docker cp dummy:/usr/share/nginx/html "$PWD/dist/html/"

docker rm -f dummy

docker build \
--tag tmp-fat \
--file ".github/Dockerfile.regenerate$target" \
"$PWD/dist"

mint slim \
--target tmp-fat \
--tag tmp \
--preserve-path /usr/share/nginx/html

docker tag tmp "$image"
docker push "$image"

echo ""
echo "Finished regenerating $image"
echo ""

0 comments on commit 2baddbb

Please sign in to comment.