Skip to content

Commit bbd02ef

Browse files
authored
Merge pull request #22 from bitofsky/container-tag-slim
Container tag slim
2 parents 515d199 + 1269d54 commit bbd02ef

3 files changed

Lines changed: 104 additions & 58 deletions

File tree

.github/workflows/docker-publish.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ on:
99
#schedule:
1010
# - cron: '35 11 * * *'
1111
push:
12-
branches: [ main ]
12+
branches: [ main, container-tag-slim ]
1313
# Publish semver tags as releases.
1414
tags: [ 'v*.*.*' ]
1515
pull_request:
16-
branches: [ main ]
16+
branches: [ main, container-tag-slim ]
1717

1818
env:
1919
# Use docker.io for Docker Hub if empty

Dockerfile

Lines changed: 10 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,19 @@
1-
FROM node:24.0.2-slim
1+
FROM alpine:3.22
22

3-
ENV DEBIAN_FRONTEND noninteractive
4-
ENV PNPM_VERSION 10.11.0
5-
ENV TURBO_VERSION 2.5.3
6-
ENV TSX_VERSION 4.19.4
7-
ENV TS_NODE 10.9.2
8-
ENV SWC_CORE 1.11.24
9-
ENV AWS_CLI 2.27.19
10-
ENV BUILDKIT_VERSION 0.21.1
3+
ENV AWS_CLI=2.27.25-r0
114

12-
RUN apt-get update -y \
13-
&& apt-get install -y --no-install-recommends \
14-
software-properties-common \
5+
RUN apk update \
6+
&& apk add --no-cache \
157
ca-certificates \
16-
build-essential \
8+
build-base \
9+
bash \
1710
wget \
1811
jq \
1912
patch \
20-
python3 \
2113
curl \
2214
unzip \
23-
git \
24-
&& apt-get clean
15+
aws-cli=${AWS_CLI} \
16+
# docker cli tool
17+
skopeo
2518

26-
# install awscli v2. see https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html
27-
RUN curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64-${AWS_CLI}.zip" -o /tmp/awscliv2.zip \
28-
&& unzip /tmp/awscliv2.zip -d /tmp/ \
29-
&& /tmp/aws/install \
30-
&& rm /tmp/awscliv2.zip \
31-
&& rm -rf /tmp/aws
32-
33-
# install node packages
34-
RUN npm i -g pnpm@${PNPM_VERSION} turbo@${TURBO_VERSION} tsx@${TSX_VERSION} ts-node@${TS_NODE} @swc/core@${SWC_CORE}
35-
36-
RUN curl -L "https://github.com/moby/buildkit/releases/download/v${BUILDKIT_VERSION}/buildkit-v${BUILDKIT_VERSION}.linux-amd64.tar.gz" -o /tmp/buildkit.tar.gz \
37-
&& mkdir -p /tmp/buildkit \
38-
&& tar -C /tmp/buildkit -xzf /tmp/buildkit.tar.gz \
39-
&& mv /tmp/buildkit/bin/buildctl /usr/bin/buildctl \
40-
&& chmod a+x /usr/bin/buildctl \
41-
&& rm -rf /tmp/buildkit \
42-
&& rm /tmp/buildkit.tar.gz
43-
44-
# install kubectl
45-
RUN curl -L "https://dl.k8s.io/release/v1.30.13/bin/linux/amd64/kubectl" -o "/usr/bin/kubectl-v1.30" \
46-
&& curl -L "https://dl.k8s.io/release/v1.31.9/bin/linux/amd64/kubectl" -o "/usr/bin/kubectl-v1.31" \
47-
&& curl -L "https://dl.k8s.io/release/v1.32.5/bin/linux/amd64/kubectl" -o "/usr/bin/kubectl-v1.32" \
48-
&& chmod a+x /usr/bin/kubectl*
49-
50-
RUN ln -s /usr/bin/kubectl-v1.32 /usr/bin/kubectl
51-
52-
# install golang
53-
COPY --from=golang:1.22.0 /usr/local/go/ /usr/local/go/
54-
ENV GOPATH /go
55-
ENV PATH $GOPATH/bin:/usr/local/go/bin:/usr/bin:${PATH}
56-
57-
# install amazon-ecr-credential-helper
58-
RUN curl -L "https://amazon-ecr-credential-helper-releases.s3.us-east-2.amazonaws.com/0.9.1/linux-amd64/docker-credential-ecr-login" -o "/usr/bin/docker-credential-ecr-login" \
59-
&& chmod a+x /usr/bin/docker-credential-ecr-login
60-
61-
RUN mkdir -p "$GOPATH/src" "$GOPATH/bin" && chmod -R 777 "$GOPATH"
62-
63-
# install uv
64-
# https://docs.astral.sh/uv/reference/installer/#unmanaged-installations
65-
RUN curl -LsSf https://astral.sh/uv/install.sh | env UV_UNMANAGED_INSTALL="/usr/bin" sh
19+
COPY script /script

script/add-container-tag

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
#!/bin/bash -e
2+
3+
add_docker_tag() {
4+
local IMAGE_PATH="$1"
5+
local NEW_TAG="$2"
6+
local USERNAME="$3"
7+
local PASSWORD="$4"
8+
9+
local REGISTRY_URL=$(echo $IMAGE_PATH | cut -d'/' -f1)
10+
local REPO_PATH=$(echo $IMAGE_PATH | cut -d'/' -f2- | cut -d':' -f1)
11+
local CURRENT_TAG=$(echo $IMAGE_PATH | cut -d':' -f2)
12+
13+
# 붙일 태그가 없으면 에러
14+
if [[ -z "$CURRENT_TAG" ]]; then
15+
echo "Error: Current tag not found in image path '$IMAGE_PATH'"
16+
return 1
17+
fi
18+
19+
if [[ -z "$NEW_TAG" ]]; then
20+
echo "Error: New tag is empty"
21+
return 1
22+
fi
23+
24+
echo "Start tagging: $REGISTRY_URL/$REPO_PATH, $CURRENT_TAG -> $NEW_TAG"
25+
26+
local SOURCE_IMAGE="docker://$REGISTRY_URL/$REPO_PATH:$CURRENT_TAG"
27+
local DEST_IMAGE="docker://$REGISTRY_URL/$REPO_PATH:$NEW_TAG"
28+
29+
local AUTH_OPTS=""
30+
if [[ -n "$USERNAME" && -n "$PASSWORD" ]]; then
31+
echo "Using provided credentials for authentication: user=$USERNAME password=$PASSWORD"
32+
AUTH_OPTS="--src-creds $USERNAME:$PASSWORD --dest-creds $USERNAME:$PASSWORD"
33+
fi
34+
35+
echo "Adding new tag '$NEW_TAG'..."
36+
37+
if skopeo copy $AUTH_OPTS "$SOURCE_IMAGE" "$DEST_IMAGE"; then
38+
echo "Successfully added tag '$NEW_TAG' to $IMAGE_PATH"
39+
return 0
40+
else
41+
echo "Error: Failed to add tag '$NEW_TAG'"
42+
return 1
43+
fi
44+
}
45+
46+
47+
TAG_TO_ADD=$1
48+
DOCKER_REGISTRY=$2
49+
TOKEN=$3
50+
51+
if [ -z "$TAG_TO_ADD" ] || [ -z "$DOCKER_REGISTRY" ]; then
52+
echo "Usage: echo -e 'image1\\nimage2\\nimage3' | $0 <tag_to_add> <docker_registry> [token]"
53+
exit 1
54+
fi
55+
56+
# if ECR
57+
if [[ "$DOCKER_REGISTRY" == *".dkr.ecr."* ]]; then
58+
USERNAME="AWS"
59+
PASSWORD=$(aws ecr get-login-password --region us-east-1)
60+
else
61+
USERNAME=$(echo "$TOKEN" | base64 -d | cut -d: -f1)
62+
PASSWORD=$(echo "$TOKEN" | base64 -d | cut -d: -f2)
63+
fi
64+
65+
if [[ -z "$PASSWORD" && "$DOCKER_REGISTRY" == *".dkr.ecr."* ]]; then
66+
echo "Error: ECR token is required for ECR registry"
67+
exit 1
68+
fi
69+
70+
if [[ -z "$TOKEN" ]]; then
71+
echo "Error: Token is required for non-ECR registry"
72+
exit 1
73+
fi
74+
75+
# stdin에서 이미지 목록을 배열로 읽기
76+
mapfile -t IMAGES
77+
if [ ${#IMAGES[@]} -eq 0 ]; then
78+
echo "Error: No images found"
79+
exit 1
80+
fi
81+
82+
for IMAGE in "${IMAGES[@]}"; do
83+
if [[ $IMAGE != *"$DOCKER_REGISTRY"* ]]; then
84+
echo "Skipping: $IMAGE (not from $DOCKER_REGISTRY)"
85+
continue
86+
fi
87+
88+
echo "add_docker_tag $IMAGE $TAG_TO_ADD $USERNAME"
89+
add_docker_tag "$IMAGE" "$TAG_TO_ADD" "$USERNAME" "$PASSWORD" &
90+
done
91+
wait
92+

0 commit comments

Comments
 (0)