From 2a12e8a9de7bf1d42fc237d8fa2589d95ba83c05 Mon Sep 17 00:00:00 2001 From: yangw Date: Sat, 23 Sep 2023 21:35:54 +0800 Subject: [PATCH] Support build image on multi arch (#46) * Support build image on multi arch(disable pushing) Signed-off-by: drivebyer * Enable push image Signed-off-by: drivebyer --------- Signed-off-by: drivebyer --- .github/workflows/push-image.yaml | 86 ++++++++++++++++++++++--------- Dockerfile | 8 ++- Dockerfile.exporter | 14 +++-- Dockerfile.sentinel | 8 ++- 4 files changed, 83 insertions(+), 33 deletions(-) diff --git a/.github/workflows/push-image.yaml b/.github/workflows/push-image.yaml index a5fbd59..5831e6e 100644 --- a/.github/workflows/push-image.yaml +++ b/.github/workflows/push-image.yaml @@ -4,42 +4,80 @@ on: push: branches: [master] +env: + REDIS_VERSION: latest + REDIS_SENTINEL_VERSION: latest + REDIS_EXPORTER_VERSION: latest + jobs: build_redis: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - name: Checkout + uses: actions/checkout@v3 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 - name: Login to Quay - run: docker login quay.io -u ${{ secrets.QUAY_USERNAME }} -p ${{ secrets.QUAY_PASSWORD }} - - name: Build and push Redis - env: - REDIS_VERSION: latest - run: | - docker build . --file Dockerfile --tag quay.io/opstree/redis:${REDIS_VERSION} - docker push quay.io/opstree/redis:${REDIS_VERSION} + uses: docker/login-action@v2 + with: + registry: quay.io + username: ${{ secrets.QUAY_USERNAME }} + password: ${{ secrets.QUAY_PASSWORD }} + - name: Build and push multi-arch latest image + uses: docker/build-push-action@v2 + with: + context: . + file: Dockerfile + platforms: linux/amd64,linux/arm64 + push: true + tags: quay.io/opstree/redis:${{ env.REDIS_VERSION }} build_redis_sentinel: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - name: Checkout + uses: actions/checkout@v3 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 - name: Login to Quay - run: docker login quay.io -u ${{ secrets.QUAY_USERNAME }} -p ${{ secrets.QUAY_PASSWORD }} - - name: Build and push Redis Sentinel - env: - REDIS_SENTINEL_VERSION: latest - run: | - docker build . --file Dockerfile.sentinel --tag quay.io/opstree/redis-sentinel:${REDIS_SENTINEL_VERSION} - docker push quay.io/opstree/redis-sentinel:${REDIS_SENTINEL_VERSION} + uses: docker/login-action@v2 + with: + registry: quay.io + username: ${{ secrets.QUAY_USERNAME }} + password: ${{ secrets.QUAY_PASSWORD }} + - name: Build and push multi-arch latest image + uses: docker/build-push-action@v2 + with: + context: . + file: Dockerfile.sentinel + platforms: linux/amd64,linux/arm64 + push: true + tags: quay.io/opstree/redis-sentinel:${{ env.REDIS_SENTINEL_VERSION }} build_redis_exporter: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - name: Checkout + uses: actions/checkout@v3 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 - name: Login to Quay - run: docker login quay.io -u ${{ secrets.QUAY_USERNAME }} -p ${{ secrets.QUAY_PASSWORD }} - - name: Build and push Redis Exporter - env: - REDIS_EXPORTER_VERSION: latest - run: | - docker build . --file Dockerfile.exporter --tag quay.io/opstree/redis-exporter:${REDIS_EXPORTER_VERSION} - docker push quay.io/opstree/redis-exporter:${REDIS_EXPORTER_VERSION} + uses: docker/login-action@v2 + with: + registry: quay.io + username: ${{ secrets.QUAY_USERNAME }} + password: ${{ secrets.QUAY_PASSWORD }} + - name: Build and push multi-arch latest image + uses: docker/build-push-action@v2 + with: + context: . + file: Dockerfile.exporter + platforms: linux/amd64,linux/arm64 + push: true + tags: quay.io/opstree/redis-exporter:${{ env.REDIS_EXPORTER_VERSION }} \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index ea7c3e1..2df554e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,8 +2,10 @@ FROM alpine:3.15 as builder MAINTAINER Opstree Solutions +ARG TARGETARCH + LABEL VERSION=1.0 \ - ARCH=AMD64 \ + ARCH=$TARGETARCH \ DESCRIPTION="A production grade performance tuned redis docker image created by Opstree Solutions" ARG REDIS_DOWNLOAD_URL="http://download.redis.io/" @@ -23,8 +25,10 @@ FROM alpine:3.15 MAINTAINER Opstree Solutions +ARG TARGETARCH + LABEL VERSION=1.0 \ - ARCH=AMD64 \ + ARCH=$TARGETARCH \ DESCRIPTION="A production grade performance tuned redis docker image created by Opstree Solutions" COPY --from=builder /usr/local/bin/redis-server /usr/local/bin/redis-server diff --git a/Dockerfile.exporter b/Dockerfile.exporter index 08a8382..751aabb 100644 --- a/Dockerfile.exporter +++ b/Dockerfile.exporter @@ -1,21 +1,25 @@ FROM alpine:3.15 as builder +ARG TARGETARCH + ARG EXPORTER_URL="https://github.com/oliver006/redis_exporter/releases/download" ARG REDIS_EXPORTER_VERSION="1.48.0" RUN apk add --no-cache curl ca-certificates && \ - curl -fL -Lo /tmp/redis_exporter-v${REDIS_EXPORTER_VERSION}.linux-amd64.tar.gz \ - ${EXPORTER_URL}/v${REDIS_EXPORTER_VERSION}/redis_exporter-v${REDIS_EXPORTER_VERSION}.linux-amd64.tar.gz && \ - cd /tmp && tar -xvzf redis_exporter-v${REDIS_EXPORTER_VERSION}.linux-amd64.tar.gz && \ - mv redis_exporter-v${REDIS_EXPORTER_VERSION}.linux-amd64 redis_exporter + curl -fL -Lo /tmp/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 && \ + cd /tmp && 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 +ARG TARGETARCH + MAINTAINER Opstree Solutions LABEL VERSION=1.0 \ - ARCH=AMD64 \ + ARCH=$TARGETARCH \ DESCRIPTION="A production grade redis exporter docker image created by Opstree Solutions" COPY --from=builder /etc/ssl/certs /etc/ssl/certs diff --git a/Dockerfile.sentinel b/Dockerfile.sentinel index 1c34cfa..912a236 100644 --- a/Dockerfile.sentinel +++ b/Dockerfile.sentinel @@ -1,7 +1,9 @@ FROM alpine:3.15 as builder +ARG TARGETARCH + LABEL VERSION=1.0 \ - ARCH=AMD64 \ + ARCH=$TARGETARCH \ DESCRIPTION="A production grade performance tuned redis docker image created by Opstree Solutions" ARG REDIS_DOWNLOAD_URL="http://download.redis.io/" @@ -19,8 +21,10 @@ RUN curl -fL -Lo /tmp/redis-${REDIS_SENTINEL_VERSION}.tar.gz ${REDIS_DOWNLOAD_UR FROM alpine:3.15 +ARG TARGETARCH + LABEL VERSION=1.0 \ - ARCH=AMD64 \ + ARCH=$TARGETARCH \ DESCRIPTION="A production grade performance tuned redis docker image created by Opstree Solutions"