forked from docker-library/mysql
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request docker-library#730 from infosiftr/jq-template
Add initial jq-based templating engine
- Loading branch information
Showing
13 changed files
with
337 additions
and
72 deletions.
There are no files selected for viewing
This file contains 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,3 @@ | ||
/*.*/**/Dockerfile* linguist-generated | ||
/*.*/**/docker-entrypoint.sh linguist-generated | ||
Dockerfile* linguist-language=Dockerfile |
This file contains 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@v2 | ||
- name: Apply Templates | ||
run: ./apply-templates.sh | ||
- name: Check Git Status | ||
run: | | ||
status="$(git status --short)" | ||
[ -z "$status" ] |
This file contains 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 |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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,45 @@ | ||
#!/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 | ||
wget -qO "$jqt" 'https://github.com/docker-library/bashbrew/raw/5f0c26381fb7cc78b2d217d58007800bdcfbcfa1/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 | ||
|
||
debianVersion="$(jq -r '.[env.version].debian // ""' versions.json)" | ||
if [ -n "$debianVersion" ]; then | ||
dockerfile='Dockerfile.debian' | ||
|
||
{ | ||
generated_warning | ||
gawk -f "$jqt" "template/$dockerfile" | ||
} > "$version/$dockerfile" | ||
fi | ||
|
||
cp -a template/docker-entrypoint.sh "$version/docker-entrypoint.sh" | ||
done |
This file contains 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 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,110 @@ | ||
FROM debian:{{ .debian.suite }}-slim | ||
|
||
# add our user and group first to make sure their IDs get assigned consistently, regardless of whatever dependencies get added | ||
RUN groupadd -r mysql && useradd -r -g mysql mysql | ||
|
||
RUN apt-get update && apt-get install -y --no-install-recommends gnupg dirmngr && rm -rf /var/lib/apt/lists/* | ||
|
||
# add gosu for easy step-down from root | ||
# https://github.com/tianon/gosu/releases | ||
ENV GOSU_VERSION 1.12 | ||
RUN set -eux; \ | ||
savedAptMark="$(apt-mark showmanual)"; \ | ||
apt-get update; \ | ||
apt-get install -y --no-install-recommends ca-certificates wget; \ | ||
rm -rf /var/lib/apt/lists/*; \ | ||
dpkgArch="$(dpkg --print-architecture | awk -F- '{ print $NF }')"; \ | ||
wget -O /usr/local/bin/gosu "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$dpkgArch"; \ | ||
wget -O /usr/local/bin/gosu.asc "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$dpkgArch.asc"; \ | ||
export GNUPGHOME="$(mktemp -d)"; \ | ||
gpg --batch --keyserver hkps://keys.openpgp.org --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4; \ | ||
gpg --batch --verify /usr/local/bin/gosu.asc /usr/local/bin/gosu; \ | ||
gpgconf --kill all; \ | ||
rm -rf "$GNUPGHOME" /usr/local/bin/gosu.asc; \ | ||
apt-mark auto '.*' > /dev/null; \ | ||
[ -z "$savedAptMark" ] || apt-mark manual $savedAptMark > /dev/null; \ | ||
apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false; \ | ||
chmod +x /usr/local/bin/gosu; \ | ||
gosu --version; \ | ||
gosu nobody true | ||
|
||
RUN mkdir /docker-entrypoint-initdb.d | ||
|
||
RUN apt-get update && apt-get install -y --no-install-recommends \ | ||
# for MYSQL_RANDOM_ROOT_PASSWORD | ||
pwgen \ | ||
{{ | ||
if env.version != "5.6" then ( | ||
-}} | ||
# for mysql_ssl_rsa_setup | ||
openssl \ | ||
{{ ) else "" end -}} | ||
# FATAL ERROR: please install the following Perl modules before executing /usr/local/mysql/scripts/mysql_install_db: | ||
# File::Basename | ||
# File::Copy | ||
# Sys::Hostname | ||
# Data::Dumper | ||
perl \ | ||
# install "xz-utils" for .sql.xz docker-entrypoint-initdb.d files | ||
xz-utils \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
|
||
RUN set -ex; \ | ||
# gpg: key 5072E1F5: public key "MySQL Release Engineering <[email protected]>" imported | ||
key='A4A9406876FCBD3C456770C88C718D3B5072E1F5'; \ | ||
export GNUPGHOME="$(mktemp -d)"; \ | ||
gpg --batch --keyserver ha.pool.sks-keyservers.net --recv-keys "$key"; \ | ||
gpg --batch --export "$key" > /etc/apt/trusted.gpg.d/mysql.gpg; \ | ||
gpgconf --kill all; \ | ||
rm -rf "$GNUPGHOME"; \ | ||
apt-key list > /dev/null | ||
|
||
ENV MYSQL_MAJOR {{ env.version }} | ||
ENV MYSQL_VERSION {{ .debian.version }} | ||
|
||
RUN echo 'deb http://repo.mysql.com/apt/debian/ {{ .debian.suite }} mysql-{{ env.version }}' > /etc/apt/sources.list.d/mysql.list | ||
|
||
# the "/var/lib/mysql" stuff here is because the mysql-server postinst doesn't have an explicit way to disable the mysql_install_db codepath besides having a database already "configured" (ie, stuff in /var/lib/mysql/mysql) | ||
# also, we set debconf keys to make APT a little quieter | ||
RUN { \ | ||
echo mysql-community-server mysql-community-server/data-dir select ''; \ | ||
echo mysql-community-server mysql-community-server/root-pass password ''; \ | ||
echo mysql-community-server mysql-community-server/re-root-pass password ''; \ | ||
echo mysql-community-server mysql-community-server/remove-test-db select false; \ | ||
} | debconf-set-selections \ | ||
&& apt-get update \ | ||
&& apt-get install -y \ | ||
{{ if env.version == "5.6" or env.version == "5.7" then ( -}} | ||
mysql-server="${MYSQL_VERSION}" \ | ||
# comment out a few problematic configuration values | ||
&& find /etc/mysql/ -name '*.cnf' -print0 \ | ||
| xargs -0 grep -lZE '^(bind-address|log)' \ | ||
| xargs -rt -0 sed -Ei 's/^(bind-address|log)/#&/' \ | ||
# don't reverse lookup hostnames, they are usually another container | ||
&& echo '[mysqld]\nskip-host-cache\nskip-name-resolve' > /etc/mysql/conf.d/docker.cnf \ | ||
{{ ) else ( -}} | ||
mysql-community-client="${MYSQL_VERSION}" \ | ||
mysql-community-server-core="${MYSQL_VERSION}" \ | ||
{{ ) end -}} | ||
&& rm -rf /var/lib/apt/lists/* \ | ||
&& rm -rf /var/lib/mysql && mkdir -p /var/lib/mysql /var/run/mysqld \ | ||
&& chown -R mysql:mysql /var/lib/mysql /var/run/mysqld \ | ||
# ensure that /var/run/mysqld (used for socket and lock files) is writable regardless of the UID our mysqld instance ends up having at runtime | ||
&& chmod 1777 /var/run/mysqld /var/lib/mysql | ||
|
||
VOLUME /var/lib/mysql | ||
|
||
{{ if env.version != "5.6" and env.version != "5.7" then ( -}} | ||
# Config files | ||
COPY config/ /etc/mysql/ | ||
{{ ) else "" end -}} | ||
COPY docker-entrypoint.sh /usr/local/bin/ | ||
RUN ln -s usr/local/bin/docker-entrypoint.sh /entrypoint.sh # backwards compat | ||
ENTRYPOINT ["docker-entrypoint.sh"] | ||
|
||
{{ if env.version != "5.6" then ( -}} | ||
EXPOSE 3306 33060 | ||
{{ ) else ( -}} | ||
EXPOSE 3306 | ||
{{ ) end -}} | ||
CMD ["mysqld"] |
File renamed without changes.
Oops, something went wrong.