Skip to content

Commit 32c48d4

Browse files
committed
feat(runtime): install mc to PATH and precreate ~/.mc (OpenShift-safe); simplify mirrio.sh
1 parent 2a2831c commit 32c48d4

2 files changed

Lines changed: 29 additions & 11 deletions

File tree

Dockerfile

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,27 @@
11
FROM ghcr.io/containeroo/alpine-toolbox:3.0.0
22

3+
ENV HOME=/work \
4+
MC_CONFIG_DIR=/work/.mc
5+
36
# renovate: datasource=github-tags depName=minio/mc extractVersion=^RELEASE\\.(?<major>\\d+)-(?<minor>\\d+)-(?<patch>\\d+)T.*Z(-(?<compatibility>.*))?$
47
ARG MINIO_VERSION=RELEASE.2023-10-14T01-57-03Z
58

6-
RUN wget -O /work/mc https://dl.min.io/client/mc/release/linux-amd64/mc && \
7-
chmod +x /work/mc
8-
9+
# App script
910
ADD mirrio.sh /work/mirrio.sh
11+
USER root
12+
RUN chmod 0755 /work/mirrio.sh
13+
14+
# Install mc (version-pinned)
15+
ADD https://dl.min.io/client/mc/release/linux-amd64/archive/mc.${MINIO_VERSION} /usr/local/bin/mc
16+
RUN chmod 0755 /usr/local/bin/mc
17+
18+
# OpenShift-friendly: group 0, g+w, setgid
19+
RUN install -d -o 0 -g 0 -m 2775 /work/.mc \
20+
&& ln -sfn /work/.mc /.mc
21+
22+
# Drop to non-root (your base convention)
23+
ARG RUNTIME_USER=10001
24+
ARG RUNTIME_GROUP=0
25+
USER ${RUNTIME_USER}:${RUNTIME_GROUP}
1026

11-
ENTRYPOINT ["/work/mirrio.sh"]
27+
CMD ["/usr/bin/catatonit", "--", "/work/mirrio.sh"]

mirrio.sh

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
#!/usr/bin/env bash
22
set -o errexit
33
set -o pipefail
4+
set -o nounset
45

56
JOB_NAME=${JOB_NAME:-mirrIO}
67
RETENTION=${RETENTION:-30d0h0m}
7-
ADDITIONAL_PARAMETERS=${ADDITIONAL_PARAMETERS:---quiet}
8-
MC_BINARY=${MC_BINARY:-/work/mc}
9-
MC_CONFIG_DIR=${MC_CONFIG_DIR:-/work/.mc}
10-
mkdir -p "$MC_CONFIG_DIR"
8+
ADDITIONAL_PARAMETERS=${ADDITIONAL_PARAMETERS:-}
119

12-
# mc wrapper to use config dir
13-
mc() { "$MC_BINARY" --config-dir "$MC_CONFIG_DIR" "$@"; }
10+
# Prefer MC_CONFIG_DIR if set, otherwise fall back to $HOME/.mc
11+
MC_CONFIG_DIR="${MC_CONFIG_DIR:-${HOME}/.mc}"
12+
mkdir -p "${MC_CONFIG_DIR}"
1413

1514
pushgateway() {
1615
if [[ -n "${PUSHGATEWAY_URL:-}" ]]; then
@@ -25,7 +24,7 @@ EOF
2524

2625
check_env() {
2726
for var in "$@"; do
28-
if [[ -z "${!var}" ]]; then
27+
if [[ -z "${!var:-}" ]]; then
2928
echo "${var} is not set!"
3029
exit 1
3130
fi
@@ -47,12 +46,15 @@ check_env \
4746
SOURCE_BUCKET \
4847
DESTINATION_BUCKET
4948

49+
# If anything errors after here, mark failure + exit
5050
trap 'notify; exit 1' ERR
51+
trap 'notify; exit 1' SIGINT SIGTERM
5152

5253
# Split extra parameters into an array so multiple flags work
5354
# shellcheck disable=SC2206
5455
read -r -a MC_MIRROR_ARGS <<<"${ADDITIONAL_PARAMETERS}"
5556

57+
# Use env-based config dir (MC_CONFIG_DIR) — no wrapper / flag needed
5658
mc alias set source "${SOURCE_URL}" "${SOURCE_ACCESSKEY}" "${SOURCE_SECRETKEY}" --api S3v4
5759
mc alias set destination "${DESTINATION_URL}" "${DESTINATION_ACCESSKEY}" "${DESTINATION_SECRETKEY}" --api S3v4
5860

0 commit comments

Comments
 (0)