Skip to content

Commit 6024cd0

Browse files
committed
remove s6-overlay for cloud run support
1 parent fae6ba6 commit 6024cd0

File tree

9 files changed

+344
-48
lines changed

9 files changed

+344
-48
lines changed

.github/workflows/build-push.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
fail-fast: false
1010
matrix:
1111
dir:
12-
- go1.25
12+
- base
1313
uses: libops/.github/.github/workflows/build-push-ghcr.yaml@main
1414
with:
1515
image: ${{ matrix.dir }}

base/Dockerfile

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
FROM alpine:3.23@sha256:865b95f46d98cf867a156fe4a135ad3fe50d2056aa3f25ed31662dff6da4eb62
2+
3+
ARG \
4+
TARGETARCH \
5+
# renovate: datasource=repology depName=alpine_3_23/bash
6+
BASH_VERSION=5.3.3-r1 \
7+
# renovate: datasource=repology depName=alpine_3_23/ca-certificates
8+
CA_CERTIFICATES_VERSION=20251003-r0 \
9+
# renovate: datasource=repology depName=alpine_3_23/curl
10+
CURL_VERSION=8.17.0-r1 \
11+
# renovate: datasource=repology depName=alpine_3_23/git
12+
GIT_VERSION=2.52.0-r0 \
13+
# renovate: datasource=repology depName=alpine_3_23/gnupg
14+
GNUPG_VERSION=2.4.8-r1 \
15+
# renovate: datasource=repology depName=alpine_3_23/go
16+
GO_VERSION=1.25.5-r0 \
17+
# renovate: datasource=repology depName=alpine_3_23/gzip
18+
GZIP_VERSION=1.14-r2 \
19+
# renovate: datasource=repology depName=alpine_3_23/jq
20+
JQ_VERSION=1.8.1-r0 \
21+
# renovate: datasource=repology depName=alpine_3_23/mariadb-client
22+
MARIADB_CLIENT_VERSION=11.4.9-r0 \
23+
# renovate: datasource=repology depName=alpine_3_23/netcat-openbsd
24+
NETCAT_OPENBSD_VERSION=1.234.1-r0 \
25+
# renovate: datasource=repology depName=alpine_3_23/openssl
26+
OPENSSL_VERSION=3.5.4-r0 \
27+
# renovate: datasource=repology depName=alpine_3_23/patch
28+
PATCH_VERSION=2.8-r0 \
29+
# renovate: datasource=repology depName=alpine_3_23/postgresql18-client
30+
POSTGRES_CLIENT_VERSION=18.1-r0 \
31+
# renovate: datasource=repology depName=alpine_3_23/procps-ng
32+
PROCPS_VERSION=4.0.5-r0 \
33+
# renovate: datasource=repology depName=alpine_3_23/shadow
34+
SHADOW_VERSION=4.18.0-r0 \
35+
# renovate: datasource=repology depName=alpine_3_23/util-linux
36+
UTIL_LINUX_VERSION=2.41.2-r0 \
37+
# renovate: datasource=repology depName=alpine_3_23/yq-go
38+
YQ_VERSION=4.49.2-r1
39+
40+
RUN --mount=type=cache,id=base-apk-${TARGETARCH},sharing=locked,target=/var/cache/apk \
41+
ln -s /var/cache/apk /etc/apk/cache && \
42+
apk add \
43+
bash=="${BASH_VERSION}" \
44+
ca-certificates=="${CA_CERTIFICATES_VERSION}" \
45+
curl=="${CURL_VERSION}" \
46+
git=="${GIT_VERSION}" \
47+
gnupg=="${GNUPG_VERSION}" \
48+
go=="${GO_VERSION}" \
49+
gzip=="${GZIP_VERSION}" \
50+
jq=="${JQ_VERSION}" \
51+
mariadb-client=="${MARIADB_CLIENT_VERSION}" \
52+
netcat-openbsd=="${NETCAT_OPENBSD_VERSION}" \
53+
openssl=="${OPENSSL_VERSION}" \
54+
patch=="${PATCH_VERSION}" \
55+
postgresql18-client=="${POSTGRES_CLIENT_VERSION}" \
56+
procps=="${PROCPS_VERSION}" \
57+
shadow=="${SHADOW_VERSION}" \
58+
util-linux=="${UTIL_LINUX_VERSION}" \
59+
yq=="${YQ_VERSION}"
60+
61+
COPY --link rootfs /
62+
63+
RUN create-service-user.sh --name goapp
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
4+
ARGS=("$@")
5+
PROGNAME=$(basename "$0")
6+
readonly ARGS PROGNAME
7+
8+
function usage() {
9+
cat <<-EOF
10+
usage: $PROGNAME options [DIR]...
11+
12+
Creates a user/group for the service and as well as a directory in /opt
13+
ensuring that all files are owned by that user/group.
14+
15+
Additional parameters are directories to be created, and owned by the new
16+
user/group.
17+
18+
OPTIONS:
19+
-n --name The name of the user (used to create user/group and home directory).
20+
-g --group The secondary group to add the user to (Optional).
21+
-h --help Show this help.
22+
-x --debug Debug this script.
23+
24+
Examples:
25+
Create user/group "activemq" and home folder /opt/activemq:
26+
$PROGNAME --name "activemq"
27+
EOF
28+
}
29+
30+
function cmdline() {
31+
local arg=
32+
for arg; do
33+
local delim=""
34+
case "$arg" in
35+
# Translate --gnu-long-options to -g (short options)
36+
--name) args="${args}-n " ;;
37+
--group) args="${args}-g " ;;
38+
--help) args="${args}-h " ;;
39+
--debug) args="${args}-x " ;;
40+
# Pass through anything else
41+
*)
42+
[[ "${arg:0:1}" == "-" ]] || delim="\""
43+
args="${args}${delim}${arg}${delim} "
44+
;;
45+
esac
46+
done
47+
48+
# Reset the positional parameters to the short options
49+
eval set -- "${args}"
50+
51+
while getopts "n:g:hx" OPTION; do
52+
case $OPTION in
53+
n)
54+
readonly NAME=${OPTARG}
55+
;;
56+
g)
57+
readonly GROUP=${OPTARG}
58+
;;
59+
h)
60+
usage
61+
exit 0
62+
;;
63+
x)
64+
set -x
65+
;;
66+
*)
67+
echo "Invalid Option: $OPTION" >&2
68+
usage
69+
exit 1
70+
;;
71+
esac
72+
done
73+
74+
if [[ ! -v NAME ]]; then
75+
echo "Missing one or more required options: --name" >&2
76+
exit 1
77+
fi
78+
79+
# All remaning parameters are directories to be created.
80+
shift $((OPTIND - 1))
81+
DIRECTORIES=("$@")
82+
readonly DIRECTORIES
83+
84+
return 0
85+
}
86+
87+
function main {
88+
local install_directory user group
89+
cmdline "${ARGS[@]}"
90+
91+
install_directory="/opt/${NAME}"
92+
user="${NAME}"
93+
group="${NAME}"
94+
mkdir -p "${install_directory}"
95+
addgroup "${group}" # Primary group is always the same as the name.
96+
# Users that run services should permit login and should not require passwords.
97+
adduser --system --disabled-password --no-create-home --ingroup "${group}" --shell /sbin/nologin --home "${install_directory}" "${user}"
98+
# User also needs to be a member of tty to write directly to /dev/stdout, etc.
99+
addgroup "${user}" tty
100+
# Optional secondary group.
101+
if [[ -v GROUP ]]; then
102+
addgroup "${NAME}" "${GROUP}"
103+
fi
104+
if ((${#DIRECTORIES[@]})); then
105+
mkdir -p "${DIRECTORIES[@]}"
106+
fi
107+
chown -R "${user}:${group}" "${install_directory}" "${DIRECTORIES[@]}"
108+
}
109+
main
Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
ARGS=("$@")
6+
PROGNAME=$(basename "$0")
7+
readonly ARGS PROGNAME
8+
9+
function usage {
10+
cat <<-EOF
11+
usage: $PROGNAME options
12+
13+
Downloads the file at the given url to the download cache folder.
14+
15+
Does not re-download the file it already exists and matches the given checksum.
16+
17+
Unpacks the file if the destination option is given.
18+
19+
Download is placed in the directory ${DOWNLOAD_CACHE_DIRECTORY}.
20+
21+
OPTIONS:
22+
-u --url The url of the file to download.
23+
-c --sha256 The sha256 checksum to use to validate the download.
24+
-d --dest The location to unpack file into (optional).
25+
-s --strip Exclude the root folder when unpacking (optional, not supported with gzip or jar).
26+
-h --help Show this help.
27+
-x --debug Debug this script.
28+
29+
Examples:
30+
$PROGNAME \\
31+
--url https://github.com/just-containers/s6-overlay/releases/download/v1.22.1.0/s6-overlay-amd64.tar.gz
32+
--sha256 7f3aba1d803543dd1df3944d014f055112cf8dadf0a583c76dd5f46578ebe3c2 \\
33+
--dest /opt/s6-overlay
34+
EOF
35+
}
36+
37+
function cmdline {
38+
local arg=
39+
local args=
40+
for arg; do
41+
local delim=""
42+
case "$arg" in
43+
# Translate --gnu-long-options to -g (short options)
44+
--url) args="${args}-u " ;;
45+
--sha256) args="${args}-c " ;;
46+
--dest) args="${args}-d " ;;
47+
--strip) args="${args}-s " ;;
48+
--help) args="${args}-h " ;;
49+
--debug) args="${args}-x " ;;
50+
# Pass through anything else
51+
*)
52+
[[ "${arg:0:1}" == "-" ]] || delim="\""
53+
args="${args}${delim}${arg}${delim} "
54+
;;
55+
esac
56+
done
57+
58+
# Reset the positional parameters to the short options
59+
eval set -- "${args}"
60+
61+
while getopts "u:c:d:shx" OPTION; do
62+
case $OPTION in
63+
u)
64+
readonly URL=${OPTARG}
65+
;;
66+
c)
67+
readonly CHECKSUM=${OPTARG}
68+
;;
69+
d)
70+
readonly DEST=${OPTARG}
71+
;;
72+
s)
73+
readonly STRIP=true
74+
;;
75+
h)
76+
usage
77+
exit 0
78+
;;
79+
x)
80+
set -x
81+
;;
82+
*)
83+
echo "Invalid Option: $OPTION" >&2
84+
usage
85+
exit 1
86+
;;
87+
esac
88+
done
89+
90+
if [[ -z $URL || -z $CHECKSUM ]]; then
91+
echo "Missing one or more required options: --url --sha256"
92+
exit 1
93+
fi
94+
95+
# All remaning parameters are files to be removed from the installation.
96+
shift $((OPTIND-1))
97+
readonly REMOVE=("$@")
98+
99+
return 0
100+
}
101+
102+
function validate {
103+
local file=${1}
104+
sha256sum "${file}" | cut -f1 -d' ' | xargs test "${CHECKSUM}" ==
105+
}
106+
107+
function unpack {
108+
local file="${1}"
109+
local dest="${2}"
110+
local args=()
111+
local filename=
112+
mkdir -p "${dest}"
113+
if [[ -v STRIP ]]; then
114+
args+=("--strip-components" "1")
115+
fi
116+
filename=$(basename "${file}")
117+
case "${file}" in
118+
*.tar.xz | *.txz)
119+
tar -xf "${file}" -C "${dest}" "${args[@]}"
120+
;;
121+
*.tar.gz | *.tgz)
122+
tar -xzf "${file}" -C "${dest}" "${args[@]}"
123+
;;
124+
*.gz | *.gzip)
125+
gunzip "${file}" -f -c > "${dest}/${filename%.*}"
126+
;;
127+
*.zip | *.war)
128+
if [[ -v STRIP ]]; then
129+
mkdir -p /tmp/unpack
130+
unzip "${file}" -d /tmp/unpack
131+
mv "$(find /tmp/unpack/ -type d -mindepth 1 -maxdepth 1)"/* "${dest}"
132+
rm -fr /tmp/unpack
133+
else
134+
unzip "${file}" -d "${dest}"
135+
fi
136+
;;
137+
*.jar)
138+
cp "${file}" "${dest}"
139+
;;
140+
*)
141+
echo "Unable to unpack ${file} please update script to support additional formats." >&2
142+
exit 1
143+
;;
144+
esac
145+
# Remove extraneous files.
146+
for i in "${REMOVE[@]}"; do
147+
rm -fr "${dest:?}/${i}"
148+
done
149+
}
150+
151+
function main {
152+
local file
153+
cmdline "${ARGS[@]}"
154+
155+
DOWNLOAD_CACHE_DIRECTORY=${DOWNLOAD_CACHE_DIRECTORY:-/tmp}
156+
file="${DOWNLOAD_CACHE_DIRECTORY:?}/$(basename "${URL}")"
157+
# Remove the downloaded file if it exist and does not match the checksum so that it can be downloaded again.
158+
if [ -f "${file}" ] && ! validate "${file}"; then
159+
rm "${file}"
160+
fi
161+
curl \
162+
-o "${DOWNLOAD_CACHE_DIRECTORY}/$(basename "${URL}")" \
163+
-z "${DOWNLOAD_CACHE_DIRECTORY}/$(basename "${URL}")" \
164+
-L "${URL}"
165+
# Return non-zero if the checksum does not match the downloaded file.
166+
validate "${file}"
167+
if [[ -v DEST ]]; then
168+
unpack "${file}" "${DEST}"
169+
fi
170+
}
171+
main

go1.25/Dockerfile

Lines changed: 0 additions & 39 deletions
This file was deleted.

go1.25/rootfs/etc/s6-overlay/s6-rc.d/goapp/dependencies.d/container-environment

Whitespace-only changes.

0 commit comments

Comments
 (0)