-
Notifications
You must be signed in to change notification settings - Fork 102
Implement jq templating #93
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
Merged
Merged
Changes from all commits
Commits
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,22 @@ | ||
name: Verify Templating | ||
|
||
on: | ||
pull_request: | ||
push: | ||
|
||
defaults: | ||
run: | ||
shell: 'bash -Eeuo pipefail -x {0}' | ||
|
||
jobs: | ||
apply-templates: | ||
name: Check For Uncomitted Changes | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Apply Templates | ||
run: ./apply-templates.sh | ||
- name: Check Git Status | ||
run: | | ||
status="$(git status --short)" | ||
[ -z "$status" ] |
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 @@ | ||
.jq-template.awk |
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,76 @@ | ||
# | ||
# NOTE: THIS DOCKERFILE IS GENERATED VIA "apply-templates.sh" | ||
# | ||
# PLEASE DO NOT EDIT IT DIRECTLY. | ||
# | ||
|
||
FROM alpine:3.18 | ||
|
||
# add our user and group first to make sure their IDs get assigned consistently, regardless of whatever dependencies get added | ||
RUN addgroup -g 11211 memcache && adduser -D -u 11211 -G memcache memcache | ||
|
||
# ensure SASL's "libplain.so" is installed as per https://github.com/memcached/memcached/wiki/SASLHowto | ||
RUN apk add --no-cache libsasl | ||
|
||
ENV MEMCACHED_VERSION 1.6.22 | ||
ENV MEMCACHED_DOWNLOAD_URL https://memcached.org/files/memcached-1.6.22.tar.gz | ||
ENV MEMCACHED_SHA1 7a691f390d59616dbebfc9e2e4942d499c39a338 | ||
|
||
RUN set -x \ | ||
\ | ||
&& apk add --no-cache --virtual .build-deps \ | ||
ca-certificates \ | ||
coreutils \ | ||
cyrus-sasl-dev \ | ||
gcc \ | ||
libc-dev \ | ||
libevent-dev \ | ||
linux-headers \ | ||
make \ | ||
openssl \ | ||
openssl-dev \ | ||
perl \ | ||
perl-io-socket-ssl \ | ||
perl-utils \ | ||
\ | ||
&& wget -O memcached.tar.gz "$MEMCACHED_DOWNLOAD_URL" \ | ||
&& echo "$MEMCACHED_SHA1 memcached.tar.gz" | sha1sum -c - \ | ||
&& mkdir -p /usr/src/memcached \ | ||
&& tar -xzf memcached.tar.gz -C /usr/src/memcached --strip-components=1 \ | ||
&& rm memcached.tar.gz \ | ||
\ | ||
&& cd /usr/src/memcached \ | ||
\ | ||
&& ./configure \ | ||
--build="$gnuArch" \ | ||
--enable-extstore \ | ||
--enable-sasl \ | ||
--enable-sasl-pwdb \ | ||
--enable-tls \ | ||
&& nproc="$(nproc)" \ | ||
&& make -j "$nproc" \ | ||
\ | ||
&& make test PARALLEL="$nproc" \ | ||
\ | ||
&& make install \ | ||
\ | ||
&& cd / && rm -rf /usr/src/memcached \ | ||
\ | ||
&& runDeps="$( \ | ||
scanelf --needed --nobanner --format '%n#p' --recursive /usr/local \ | ||
| tr ',' '\n' \ | ||
| sort -u \ | ||
| awk 'system("[ -e /usr/local/lib/" $1 " ]") == 0 { next } { print "so:" $1 }' \ | ||
)" \ | ||
&& apk add --no-network --virtual .memcached-rundeps $runDeps \ | ||
&& apk del --no-network .build-deps \ | ||
\ | ||
&& memcached -V | ||
|
||
COPY docker-entrypoint.sh /usr/local/bin/ | ||
RUN ln -s usr/local/bin/docker-entrypoint.sh /entrypoint.sh # backwards compat | ||
ENTRYPOINT ["docker-entrypoint.sh"] | ||
|
||
USER memcache | ||
EXPOSE 11211 | ||
CMD ["memcached"] |
File renamed without changes.
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,96 @@ | ||
# | ||
# NOTE: THIS DOCKERFILE IS GENERATED VIA "apply-templates.sh" | ||
# | ||
# PLEASE DO NOT EDIT IT DIRECTLY. | ||
# | ||
|
||
FROM debian:bookworm-slim | ||
|
||
# add our user and group first to make sure their IDs get assigned consistently, regardless of whatever dependencies get added | ||
RUN groupadd --system --gid 11211 memcache && useradd --system --gid memcache --uid 11211 memcache | ||
|
||
# ensure SASL's "libplain.so" is installed as per https://github.com/memcached/memcached/wiki/SASLHowto | ||
RUN set -eux; \ | ||
apt-get update; \ | ||
apt-get install -y --no-install-recommends \ | ||
libsasl2-modules \ | ||
; \ | ||
rm -rf /var/lib/apt/lists/* | ||
|
||
ENV MEMCACHED_VERSION 1.6.22 | ||
ENV MEMCACHED_DOWNLOAD_URL https://memcached.org/files/memcached-1.6.22.tar.gz | ||
ENV MEMCACHED_SHA1 7a691f390d59616dbebfc9e2e4942d499c39a338 | ||
|
||
RUN set -x \ | ||
\ | ||
&& savedAptMark="$(apt-mark showmanual)" \ | ||
&& apt-get update \ | ||
&& apt-get install -y --no-install-recommends \ | ||
ca-certificates \ | ||
dpkg-dev \ | ||
gcc \ | ||
libc6-dev \ | ||
libevent-dev \ | ||
libio-socket-ssl-perl \ | ||
libsasl2-dev \ | ||
libssl-dev \ | ||
make \ | ||
perl \ | ||
wget \ | ||
&& rm -rf /var/lib/apt/lists/* \ | ||
\ | ||
&& wget -O memcached.tar.gz "$MEMCACHED_DOWNLOAD_URL" \ | ||
&& echo "$MEMCACHED_SHA1 memcached.tar.gz" | sha1sum -c - \ | ||
&& mkdir -p /usr/src/memcached \ | ||
&& tar -xzf memcached.tar.gz -C /usr/src/memcached --strip-components=1 \ | ||
&& rm memcached.tar.gz \ | ||
\ | ||
&& cd /usr/src/memcached \ | ||
\ | ||
&& gnuArch="$(dpkg-architecture --query DEB_BUILD_GNU_TYPE)" \ | ||
&& enableExtstore="$( \ | ||
# https://github.com/docker-library/memcached/pull/38 | ||
case "$gnuArch" in \ | ||
# https://github.com/memcached/memcached/issues/381 "--enable-extstore on s390x (IBM System Z mainframe architecture) fails tests" | ||
s390x-*) ;; \ | ||
*) echo '--enable-extstore' ;; \ | ||
esac \ | ||
)" \ | ||
&& ./configure \ | ||
--build="$gnuArch" \ | ||
--enable-sasl \ | ||
--enable-sasl-pwdb \ | ||
--enable-tls \ | ||
$enableExtstore \ | ||
&& nproc="$(nproc)" \ | ||
&& make -j "$nproc" \ | ||
\ | ||
# see https://github.com/docker-library/memcached/pull/54#issuecomment-562797748 and https://bugs.debian.org/927461 for why we have to munge openssl.cnf | ||
&& sed -i.bak 's/SECLEVEL=2/SECLEVEL=1/g' /etc/ssl/openssl.cnf \ | ||
&& make test PARALLEL="$nproc" \ | ||
&& mv /etc/ssl/openssl.cnf.bak /etc/ssl/openssl.cnf \ | ||
\ | ||
&& make install \ | ||
\ | ||
&& cd / && rm -rf /usr/src/memcached \ | ||
\ | ||
&& apt-mark auto '.*' > /dev/null \ | ||
&& apt-mark manual $savedAptMark > /dev/null \ | ||
&& find /usr/local -type f -executable -exec ldd '{}' ';' \ | ||
| awk '/=>/ { so = $(NF-1); if (index(so, "/usr/local/") == 1) { next }; gsub("^/(usr/)?", "", so); print so }' \ | ||
| sort -u \ | ||
| xargs -r dpkg-query --search \ | ||
| cut -d: -f1 \ | ||
| sort -u \ | ||
| xargs -r apt-mark manual \ | ||
&& apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false \ | ||
\ | ||
&& memcached -V | ||
|
||
COPY docker-entrypoint.sh /usr/local/bin/ | ||
RUN ln -s usr/local/bin/docker-entrypoint.sh /entrypoint.sh # backwards compat | ||
ENTRYPOINT ["docker-entrypoint.sh"] | ||
|
||
USER memcache | ||
EXPOSE 11211 | ||
CMD ["memcached"] |
File renamed without changes.
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
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,73 @@ | ||
#!/usr/bin/env bash | ||
set -Eeuo pipefail | ||
|
||
[ -f versions.json ] # run "versions.sh" first | ||
|
||
cd "$(dirname "$(readlink -f "$BASH_SOURCE")")" | ||
|
||
jqt='.jq-template.awk' | ||
if [ -n "${BASHBREW_SCRIPTS:-}" ]; then | ||
jqt="$BASHBREW_SCRIPTS/jq-template.awk" | ||
elif [ "$BASH_SOURCE" -nt "$jqt" ]; then | ||
# https://github.com/docker-library/bashbrew/blob/master/scripts/jq-template.awk | ||
wget -qO "$jqt" 'https://github.com/docker-library/bashbrew/raw/9f6a35772ac863a0241f147c820354e4008edf38/scripts/jq-template.awk' | ||
fi | ||
|
||
if [ "$#" -eq 0 ]; then | ||
versions="$(jq -r 'keys | map(@sh) | join(" ")' versions.json)" | ||
eval "set -- $versions" | ||
fi | ||
|
||
generated_warning() { | ||
cat <<-EOH | ||
# | ||
# NOTE: THIS DOCKERFILE IS GENERATED VIA "apply-templates.sh" | ||
# | ||
# PLEASE DO NOT EDIT IT DIRECTLY. | ||
# | ||
|
||
EOH | ||
} | ||
|
||
for version; do | ||
export version | ||
|
||
if [ -d "$version" ]; then | ||
rm -rf "$version" | ||
fi | ||
|
||
if jq -e '.[env.version] | not' versions.json > /dev/null; then | ||
echo "skipping $version ..." | ||
continue | ||
fi | ||
|
||
variants="$(jq -r '.[env.version].variants | map(@sh) | join(" ")' versions.json)" | ||
eval "variants=( $variants )" | ||
|
||
for variant in "${variants[@]}"; do | ||
export variant | ||
|
||
echo "processing $version/$variant ..." | ||
|
||
dir="$version${variant:+/$variant}" | ||
|
||
mkdir -p "$dir" | ||
|
||
cp -f docker-entrypoint.sh "$dir/" | ||
|
||
case "$variant" in | ||
alpine*) | ||
template='Dockerfile-alpine.template' | ||
sed -i -e 's/gosu/su-exec/g' "$dir/docker-entrypoint.sh" | ||
;; | ||
*) | ||
template='Dockerfile-debian.template' | ||
;; | ||
esac | ||
|
||
{ | ||
generated_warning | ||
gawk -f "$jqt" "$template" | ||
} > "$dir/Dockerfile" | ||
done | ||
done |
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,9 @@ | ||
#!/bin/sh | ||
set -e | ||
|
||
# first arg is `-f` or `--some-option` | ||
if [ "${1#-}" != "$1" ]; then | ||
set -- memcached "$@" | ||
fi | ||
|
||
exec "$@" |
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.
I think a future goal would be to combine the Alpine and Debian templates into one to ensure that the common bits and flow remain in sync. This can be a future PR or added to this one 🤷.