From c7b8fb9fb55968e1b552e57c4a8695c95cc603ab Mon Sep 17 00:00:00 2001 From: Ben Vincent Date: Sun, 26 Jan 2025 14:50:12 +1100 Subject: [PATCH] feat: add etcd build - create rpm for etcd, etcdctl and etcdutl - manage systemd service for etcd --- rpms/etcd/3.5.18/release | 1 + rpms/etcd/Dockerfile | 25 +++++++++ rpms/etcd/nfpm.yaml | 60 ++++++++++++++++++++++ rpms/etcd/resources/etcd.service | 18 +++++++ rpms/etcd/resources/scripts/postinstall.sh | 2 + rpms/etcd/resources/scripts/postremove.sh | 3 ++ rpms/etcd/resources/scripts/preinstall.sh | 5 ++ rpms/etcd/resources/scripts/preremove.sh | 2 + 8 files changed, 116 insertions(+) create mode 100644 rpms/etcd/3.5.18/release create mode 100644 rpms/etcd/Dockerfile create mode 100644 rpms/etcd/nfpm.yaml create mode 100644 rpms/etcd/resources/etcd.service create mode 100755 rpms/etcd/resources/scripts/postinstall.sh create mode 100755 rpms/etcd/resources/scripts/postremove.sh create mode 100755 rpms/etcd/resources/scripts/preinstall.sh create mode 100755 rpms/etcd/resources/scripts/preremove.sh diff --git a/rpms/etcd/3.5.18/release b/rpms/etcd/3.5.18/release new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/rpms/etcd/3.5.18/release @@ -0,0 +1 @@ +1 diff --git a/rpms/etcd/Dockerfile b/rpms/etcd/Dockerfile new file mode 100644 index 0000000..628f8a6 --- /dev/null +++ b/rpms/etcd/Dockerfile @@ -0,0 +1,25 @@ +# Start with the AlmaLinux 8.10 base image +FROM git.query.consul/unkin/almalinux8-rpmbuilder:latest + +# Create output directory for RPMs +RUN mkdir -p /app/dist + +# Set working directory +WORKDIR /app + +ARG PACKAGE_RELEASE +ENV PACKAGE_RELEASE=${PACKAGE_RELEASE} +ARG PACKAGE_VERSION +ENV PACKAGE_VERSION=${PACKAGE_VERSION} + +# Copy nfpm.yaml from the context into the container +COPY nfpm.yaml /app/nfpm.yaml +COPY resources /app/resources + +# Download the required files +RUN wget -O /app/etcd-v${PACKAGE_VERSION}-linux-amd64.tar.gz https://github.com/etcd-io/etcd/releases/download/v${PACKAGE_VERSION}/etcd-v${PACKAGE_VERSION}-linux-amd64.tar.gz && \ + tar xf /app/etcd-v${PACKAGE_VERSION}-linux-amd64.tar.gz && \ + mv /app/etcd-v${PACKAGE_VERSION}-linux-amd64/* /app/ + +# Default command to build RPMs +CMD nfpm pkg --config /app/nfpm.yaml --target /app/dist --packager rpm diff --git a/rpms/etcd/nfpm.yaml b/rpms/etcd/nfpm.yaml new file mode 100644 index 0000000..f495f32 --- /dev/null +++ b/rpms/etcd/nfpm.yaml @@ -0,0 +1,60 @@ +# nfpm.yaml + +name: etcd +version: ${PACKAGE_VERSION} +release: ${PACKAGE_RELEASE} +arch: amd64 +platform: linux +section: default +priority: extra +description: "A distributed, reliable key-value store for the most critical data of a distributed system." + +maintainer: https://etcd.io/ +homepage: https://etcd.io/ +license: Apache-2.0 + +disable_globbing: false + +replaces: + - etcd + - etcdctl + - etcdutl + +provides: + - etcd + - etcdctl + - etcdutl + +# Files to include in the package +contents: + - src: /app/etcd + dst: /usr/bin/etcd + file_info: + mode: 0755 + owner: root + group: root + - src: /app/etcdctl + dst: /usr/bin/etcdctl + file_info: + mode: 0755 + owner: root + group: root + - src: /app/etcdutl + dst: /usr/bin/etcdutl + file_info: + mode: 0755 + owner: root + group: root + - src: /app/resources/etcd.service + dst: /usr/lib/systemd/system/etcd.service + file_info: + mode: 0644 + owner: root + group: root + +# Scripts to run during installation/removal (optional) +scripts: + preinstall: ./resources/scripts/preinstall.sh + postinstall: ./resources/scripts/postinstall.sh + preremove: ./resources/scripts/preremove.sh + postremove: ./resources/scripts/postremove.sh diff --git a/rpms/etcd/resources/etcd.service b/rpms/etcd/resources/etcd.service new file mode 100644 index 0000000..8fc0570 --- /dev/null +++ b/rpms/etcd/resources/etcd.service @@ -0,0 +1,18 @@ +[Unit] +Description=etcd key-value store +Documentation=https://github.com/etcd-io/etcd +After=network-online.target local-fs.target remote-fs.target time-sync.target +Wants=network-online.target local-fs.target remote-fs.target time-sync.target + +[Service] +User=etcd +Type=notify +Environment=ETCD_DATA_DIR=/var/lib/etcd +Environment=ETCD_NAME=%m +ExecStart=/usr/bin/etcd +Restart=always +RestartSec=10s +LimitNOFILE=40000 + +[Install] +WantedBy=multi-user.target diff --git a/rpms/etcd/resources/scripts/postinstall.sh b/rpms/etcd/resources/scripts/postinstall.sh new file mode 100755 index 0000000..50041ee --- /dev/null +++ b/rpms/etcd/resources/scripts/postinstall.sh @@ -0,0 +1,2 @@ +#!/usr/bin/env bash +systemctl daemon-reload diff --git a/rpms/etcd/resources/scripts/postremove.sh b/rpms/etcd/resources/scripts/postremove.sh new file mode 100755 index 0000000..eb463c9 --- /dev/null +++ b/rpms/etcd/resources/scripts/postremove.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash +rm -f /usr/lib/systemd/system/etcd.service +systemctl daemon-reload diff --git a/rpms/etcd/resources/scripts/preinstall.sh b/rpms/etcd/resources/scripts/preinstall.sh new file mode 100755 index 0000000..9c8237c --- /dev/null +++ b/rpms/etcd/resources/scripts/preinstall.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env bash +groupadd --system etcd +useradd --system --shell /sbin/nologin --no-create-home --home-dir /var/lib/etcd --gid etcd etcd +mkdir -p /var/lib/etcd +chown etcd:etcd /var/lib/etcd diff --git a/rpms/etcd/resources/scripts/preremove.sh b/rpms/etcd/resources/scripts/preremove.sh new file mode 100755 index 0000000..1021f6c --- /dev/null +++ b/rpms/etcd/resources/scripts/preremove.sh @@ -0,0 +1,2 @@ +#!/usr/bin/env bash +systemctl stop etcd.service