Skip to content

Commit b41621f

Browse files
committed
static etcdctl
1 parent f5c8ced commit b41621f

2 files changed

Lines changed: 154 additions & 0 deletions

File tree

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
name: 'build docker images: static etcdctl'
2+
3+
on:
4+
#push:
5+
# branches:
6+
# - 'main'
7+
# - 'master'
8+
# paths:
9+
# - 'static-etcdctl.scratch.Dockerfile'
10+
# - '.github/workflows/build_docker_images-static-etcdctl.yaml'
11+
workflow_dispatch:
12+
schedule:
13+
- cron: '30 5 25 * *' # At 05:30 on day-of-month 25.
14+
15+
defaults:
16+
run:
17+
shell: bash
18+
19+
jobs:
20+
docker:
21+
runs-on: ubuntu-latest
22+
steps:
23+
- name: Checkout
24+
uses: actions/checkout@v4
25+
26+
- name: Shell-Script
27+
id: script
28+
run: |
29+
BUILD_DATE="$(date -u +'%Y-%m-%dT%H:%M:%SZ')"
30+
BUILD_DATE_NUMERIC="${BUILD_DATE//[^[:digit:]]/}"
31+
COMMIT_HASH=${GITHUB_SHA::7}
32+
GIT_URL=$(echo "${GITHUB_SERVER_URL}" | awk -F/ '{print $3}' | sed 's/\/*$//')
33+
GIT_URL=$(echo "$GIT_URL" | sed 's/github\.com/ghcr\.io/g') # GIT_URL switch to ghcr.io registry for GitHub
34+
GIT_REPO=${GITHUB_REPOSITORY,,}
35+
GIT_REPO_SHORT=${GIT_REPO#*/}
36+
GIT_REPO_SHORT=${GIT_REPO_SHORT#"docker-"}
37+
DOCKER_REPO=${{ secrets.DOCKER_USERNAME }}/${GIT_REPO_SHORT}
38+
REDHAT_QUAY_REPO=${{ secrets.REDHAT_QUAY_USERNAME }}/${GIT_REPO_SHORT}
39+
40+
#echo "ENVs: BUILD_DATE=${BUILD_DATE}, BUILD_DATE_NUMERIC=${BUILD_DATE_NUMERIC}, COMMIT_HASH=${COMMIT_HASH}, GIT_URL=${GIT_URL}, GIT_REPO=${GIT_REPO}"
41+
42+
# Set output parameters to action.
43+
echo "build_date=${BUILD_DATE}" >> "$GITHUB_OUTPUT"
44+
echo "build_date_numeric=${BUILD_DATE_NUMERIC}" >> "$GITHUB_OUTPUT"
45+
echo "commit_hash=${COMMIT_HASH}" >> "$GITHUB_OUTPUT"
46+
echo "git_url=${GIT_URL}" >> "$GITHUB_OUTPUT"
47+
echo "git_repo=${GIT_REPO}" >> "$GITHUB_OUTPUT"
48+
echo "docker_repo=${DOCKER_REPO}" >> "$GITHUB_OUTPUT"
49+
echo "redhat_quay_repo=${REDHAT_QUAY_REPO}" >> "$GITHUB_OUTPUT"
50+
51+
# static etcdctl
52+
ETCD_VERSION=$(wget -qO- https://api.github.com/repos/etcd-io/etcd/releases/latest | grep 'tag_name' | cut -d\" -f4)
53+
echo "ETCD_VERSION=${ETCD_VERSION}"
54+
echo "etcd_version=${ETCD_VERSION}" >> "$GITHUB_OUTPUT"
55+
56+
- name: Set up QEMU
57+
id: qemu
58+
uses: docker/setup-qemu-action@v3
59+
with:
60+
image: tonistiigi/binfmt:latest
61+
platforms: all
62+
63+
- name: Set up Docker Buildx
64+
id: buildx
65+
uses: docker/setup-buildx-action@v3
66+
67+
- name: Login to GIT Container Registry
68+
uses: docker/login-action@v3
69+
with:
70+
registry: ${{ steps.script.outputs.git_url }}
71+
username: ${{ github.repository_owner }}
72+
password: ${{ secrets.GITHUB_TOKEN }}
73+
74+
- name: Login to DockerHub Container Registry
75+
uses: docker/login-action@v3
76+
with:
77+
registry: docker.io
78+
username: ${{ secrets.DOCKER_USERNAME }}
79+
password: ${{ secrets.DOCKER_PASSWORD }}
80+
81+
- name: Login to RED HAT Quay.io Container Registry
82+
uses: docker/login-action@v3
83+
with:
84+
registry: quay.io
85+
username: ${{ secrets.REDHAT_QUAY_USERNAME }}
86+
password: ${{ secrets.REDHAT_QUAY_PASSWORD }}
87+
88+
- name: Build
89+
uses: docker/build-push-action@v6
90+
with:
91+
builder: ${{ steps.buildx.outputs.name }}
92+
context: .
93+
file: ./static-etcdctl.scratch.Dockerfile
94+
platforms: linux/amd64,linux/arm64,linux/ppc64le,linux/s390x
95+
push: true
96+
target: binary
97+
build-args: |
98+
BUILD_DATE=${{steps.script.outputs.build_date}}
99+
VCS_REF=${{steps.script.outputs.commit_hash}}
100+
ETCD_VERSION=${{steps.script.outputs.etcd_version}}
101+
tags: |
102+
docker.io/${{steps.script.outputs.docker_repo}}:static-etcdctl
103+
docker.io/${{steps.script.outputs.docker_repo}}:static-etcdctl-${{steps.script.outputs.etcd_version}}
104+
quay.io/${{steps.script.outputs.redhat_quay_repo}}:static-etcdctl
105+
${{steps.script.outputs.git_url}}/${{steps.script.outputs.git_repo}}:static-etcdctl

static-etcdctl.scratch.Dockerfile

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# build: docker build --no-cache --progress=plain --target binary --build-arg ETCD_VERSION=v3.6.5 -t tobi312/tools:static-etcdctl -f static-etcdctl.scratch.Dockerfile .
2+
ARG ETCD_VERSION
3+
FROM golang:alpine AS static-etcd
4+
5+
ARG ETCD_VERSION
6+
7+
# etcd https://github.com/etcd-io/etcd
8+
9+
SHELL ["/bin/ash", "-euxo", "pipefail", "-c"]
10+
11+
RUN \
12+
OS="$(go env GOOS)" ; \
13+
ARCH="$(go env GOARCH)" ; \
14+
TARGETARCH="${ARCH}" ; \
15+
\
16+
ETCD_VERSION=${ETCD_VERSION:-$(wget -qO- https://api.github.com/repos/etcd-io/etcd/releases/latest | grep 'tag_name' | cut -d\" -f4)} ; \
17+
echo ">> ETCD_VERSION=${ETCD_VERSION}" ; \
18+
wget -qO- "https://github.com/etcd-io/etcd/releases/download/${ETCD_VERSION}/etcd-${ETCD_VERSION}-${OS}-${TARGETARCH}.tar.gz" | tar -zxf - --strip-components=1 -C /usr/local/bin/ etcd-${ETCD_VERSION}-${OS}-${TARGETARCH}/etcdctl ; \
19+
chmod +x /usr/local/bin/etcdctl ; \
20+
echo ">> ETCD_VERSION (check): $(etcdctl version)" ; \
21+
echo ">> etcdctl Help:" ; \
22+
etcdctl --help
23+
24+
25+
FROM scratch AS binary
26+
27+
ARG ETCD_VERSION
28+
ARG VCS_REF
29+
ARG BUILD_DATE
30+
31+
LABEL org.opencontainers.image.title="etcdctl" \
32+
org.opencontainers.image.authors="etcd Community, Tobias Hargesheimer <docker@ison.ws>" \
33+
org.opencontainers.image.version="${ETCD_VERSION}" \
34+
org.opencontainers.image.created="${BUILD_DATE}" \
35+
org.opencontainers.image.revision="${VCS_REF}" \
36+
org.opencontainers.image.description="Static etcdctl - CLI for etcd key-value store" \
37+
org.opencontainers.image.documentation="https://etcd.io/" \
38+
org.opencontainers.image.licenses="Apache-2.0" \
39+
org.opencontainers.image.base.name="scratch" \
40+
org.opencontainers.image.url="https://github.com/Tob1as/docker-tools" \
41+
org.opencontainers.image.source="https://github.com/etcd-io/etcd"
42+
43+
COPY --from=static-etcd /usr/local/bin/etcdctl /usr/local/bin/etcdctl
44+
45+
RUN ["etcdctl", "version"]
46+
47+
ENTRYPOINT ["etcdctl"]
48+
#CMD ["version"]
49+
#CMD ["--help"]

0 commit comments

Comments
 (0)