From 799669a20e9258f7e26dbe7cbea7f3159620bb54 Mon Sep 17 00:00:00 2001 From: drivebyer Date: Fri, 13 Sep 2024 21:41:41 +0800 Subject: [PATCH] feat: support multi version build --- .github/workflows/cd.yaml | 23 +++++++++++++++++++---- .github/workflows/ci.yml | 2 +- Dockerfile | 11 ++++++++--- Dockerfile.exporter | 7 ++++--- Dockerfile.sentinel | 23 ++++++++++++++++------- 5 files changed, 48 insertions(+), 18 deletions(-) diff --git a/.github/workflows/cd.yaml b/.github/workflows/cd.yaml index 3a839bc..67bb751 100644 --- a/.github/workflows/cd.yaml +++ b/.github/workflows/cd.yaml @@ -1,4 +1,4 @@ -name: Docker +name: Docker Image CD on: push: @@ -11,6 +11,9 @@ env: jobs: build_redis: + strategy: + matrix: + version: [v6.2.14, v7.0.15, latest] runs-on: ubuntu-latest steps: - name: Checkout @@ -32,9 +35,14 @@ jobs: file: Dockerfile platforms: linux/amd64,linux/arm64 push: true - tags: quay.io/opstree/redis:${{ env.REDIS_VERSION }} + build-args: | + REDIS_VERSION: ${{ matrix.version }} + tags: quay.io/opstree/redis:${{ matrix.version }} build_redis_sentinel: + strategy: + matrix: + version: [v6.2.14, v7.0.15, latest] runs-on: ubuntu-latest steps: - name: Checkout @@ -56,9 +64,14 @@ jobs: file: Dockerfile.sentinel platforms: linux/amd64,linux/arm64 push: true - tags: quay.io/opstree/redis-sentinel:${{ env.REDIS_SENTINEL_VERSION }} + build-args: | + REDIS_SENTINEL_VERSION: ${{ matrix.version }} + tags: quay.io/opstree/redis-sentinel:${{ matrix.version }} build_redis_exporter: + strategy: + matrix: + version: [v1.48.0] runs-on: ubuntu-latest steps: - name: Checkout @@ -80,4 +93,6 @@ jobs: file: Dockerfile.exporter platforms: linux/amd64,linux/arm64 push: true - tags: quay.io/opstree/redis-exporter:${{ env.REDIS_EXPORTER_VERSION }} + build-args: | + REDIS_EXPORTER_VERSION: ${{ matrix.version }} + tags: quay.io/opstree/redis-exporter:${{ matrix.version }} diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4674582..e8f4444 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,7 +2,7 @@ name: Docker Image CI on: pull_request: - branches: [ "master" ] + branches: [master] jobs: build_dockerfile: diff --git a/Dockerfile b/Dockerfile index f79a317..43d66f7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,15 +8,20 @@ LABEL version=1.0 \ arch=$TARGETARCH \ description="A production grade performance tuned redis docker image created by Opstree Solutions" -ARG REDIS_DOWNLOAD_URL="http://download.redis.io/" - ARG REDIS_VERSION="stable" RUN apk add --no-cache su-exec tzdata make curl build-base linux-headers bash openssl-dev WORKDIR /tmp -RUN curl -fL -Lo redis-${REDIS_VERSION}.tar.gz ${REDIS_DOWNLOAD_URL}/redis-${REDIS_VERSION}.tar.gz && \ +RUN REDIS_VERSION=$(echo ${REDIS_VERSION} | sed 's/^v//'); \ + case "${REDIS_VERSION}" in \ + latest | stable) \ + REDIS_DOWNLOAD_URL="http://download.redis.io"; \ + *) \ + REDIS_DOWNLOAD_URL="http://download.redis.io/releases"; \ + esac; \ + curl -fL -Lo redis-${REDIS_VERSION}.tar.gz ${REDIS_DOWNLOAD_URL}/redis-${REDIS_VERSION}.tar.gz; \ tar xvzf redis-${REDIS_VERSION}.tar.gz WORKDIR /tmp/redis-${REDIS_VERSION} diff --git a/Dockerfile.exporter b/Dockerfile.exporter index 55c412d..bf924f0 100644 --- a/Dockerfile.exporter +++ b/Dockerfile.exporter @@ -8,10 +8,11 @@ ARG REDIS_EXPORTER_VERSION="1.48.0" WORKDIR /tmp -RUN apk add --no-cache curl ca-certificates && \ +RUN REDIS_EXPORTER_VERSION=$(echo ${REDIS_EXPORTER_VERSION} | sed 's/^v//'); \ + apk add --no-cache curl ca-certificates; \ curl -fL -Lo redis_exporter-v${REDIS_EXPORTER_VERSION}.linux-$TARGETARCH.tar.gz \ - ${EXPORTER_URL}/v${REDIS_EXPORTER_VERSION}/redis_exporter-v${REDIS_EXPORTER_VERSION}.linux-$TARGETARCH.tar.gz && \ - tar -xvzf redis_exporter-v${REDIS_EXPORTER_VERSION}.linux-$TARGETARCH.tar.gz && \ + ${EXPORTER_URL}/v${REDIS_EXPORTER_VERSION}/redis_exporter-v${REDIS_EXPORTER_VERSION}.linux-$TARGETARCH.tar.gz; \ + tar -xvzf redis_exporter-v${REDIS_EXPORTER_VERSION}.linux-$TARGETARCH.tar.gz; \ mv redis_exporter-v${REDIS_EXPORTER_VERSION}.linux-$TARGETARCH redis_exporter FROM scratch diff --git a/Dockerfile.sentinel b/Dockerfile.sentinel index 064f9e7..e39bf73 100644 --- a/Dockerfile.sentinel +++ b/Dockerfile.sentinel @@ -6,24 +6,33 @@ LABEL version=1.0 \ arch=$TARGETARCH \ description="A production grade performance tuned redis docker image created by Opstree Solutions" -ARG REDIS_DOWNLOAD_URL="http://download.redis.io/" - ARG REDIS_SENTINEL_VERSION="stable" RUN apk add --no-cache su-exec tzdata make curl build-base linux-headers bash openssl-dev WORKDIR /tmp -RUN curl -fL -Lo redis-${REDIS_SENTINEL_VERSION}.tar.gz ${REDIS_DOWNLOAD_URL}/redis-${REDIS_SENTINEL_VERSION}.tar.gz && \ - tar xvzf redis-${REDIS_SENTINEL_VERSION}.tar.gz && \ - arch="$(uname -m)"; \ +RUN REDIS_SENTINEL_VERSION=$(echo ${REDIS_SENTINEL_VERSION} | sed 's/^v//'); \ + case "${REDIS_SENTINEL_VERSION}" in \ + latest | stable) \ + REDIS_DOWNLOAD_URL="http://download.redis.io"; \ + *) \ + REDIS_DOWNLOAD_URL="http://download.redis.io/releases"; \ + esac; \ + \ + curl -fL -Lo redis-${REDIS_SENTINEL_VERSION}.tar.gz ${REDIS_DOWNLOAD_URL}/redis-${REDIS_SENTINEL_VERSION}.tar.gz; \ + tar xvzf redis-${REDIS_SENTINEL_VERSION}.tar.gz + +WORKDIR /tmp/redis-${REDIS_SENTINEL_VERSION} + +RUN arch="$(uname -m)"; \ extraJemallocConfigureFlags="--with-lg-page=16"; \ if [ "$arch" = "aarch64" ] || [ "$arch" = "arm64" ]; then \ sed -ri 's!cd jemalloc && ./configure !&'"$extraJemallocConfigureFlags"' !' /tmp/redis-${REDIS_SENTINEL_VERSION}/deps/Makefile; \ fi; \ export BUILD_TLS=yes; \ - make -C redis-${REDIS_SENTINEL_VERSION} all; \ - make -C redis-${REDIS_SENTINEL_VERSION} install + make all; \ + make install FROM alpine:3.15