From d35df829cac228893387d0aca780f1b20e939c66 Mon Sep 17 00:00:00 2001 From: Chingis Sandanov Date: Wed, 26 Feb 2025 15:41:15 +0700 Subject: [PATCH] add linux/arm64 variant --- .github/actions/action.yml | 19 +++++++------ .github/actions/release.sh | 33 +++++++++++++++------- .github/workflows/workflow.yml | 50 ++++++++++++++++++++++++++++++---- Makefile | 31 +++++++++++++++++---- README.md | 2 ++ 5 files changed, 104 insertions(+), 31 deletions(-) diff --git a/.github/actions/action.yml b/.github/actions/action.yml index e1cec68..af3840c 100644 --- a/.github/actions/action.yml +++ b/.github/actions/action.yml @@ -1,22 +1,23 @@ -name: Build -description: Build memcached image +name: push +description: combine multi-arch image and push inputs: version: description: version required: true - tags: - description: image tags - required: true + latest: + description: if tag latest + required: false + latest_major: + description: if tag latest major version + required: false runs: using: "composite" steps: - name: Build image env: MEMCACHED_VER: ${{ inputs.version }} - TAGS: ${{ inputs.tags }} + LATEST: ${{ inputs.latest }} + LATEST_MAJOR: ${{ inputs.latest_major }} run: | - set -e - make - make test . $GITHUB_ACTION_PATH/release.sh shell: bash diff --git a/.github/actions/release.sh b/.github/actions/release.sh index d8a3419..6d54e51 100755 --- a/.github/actions/release.sh +++ b/.github/actions/release.sh @@ -1,17 +1,30 @@ #!/usr/bin/env bash -set -e +set -exo pipefail -if [[ "${GITHUB_REF}" == refs/heads/master || "${GITHUB_REF}" == refs/tags/* ]]; then - docker login -u "${DOCKER_USERNAME}" -p "${DOCKER_PASSWORD}" +if [[ "${GITHUB_REF}" == refs/heads/master || "${GITHUB_REF}" == refs/tags/* ]]; then + minor_ver="${MEMCACHED_VER%.*}" + major_ver="${minor_ver%.*}" - if [[ "${GITHUB_REF}" == refs/tags/* ]]; then - export STABILITY_TAG="${GITHUB_REF##*/}" - fi + tags=("${minor_ver}") + + if [[ -n "${LATEST_MAJOR}" ]]; then + tags+=("${major_ver}") + fi - IFS=',' read -ra tags <<< "${TAGS}" + if [[ "${GITHUB_REF}" == refs/tags/* ]]; then + stability_tag=("${GITHUB_REF##*/}") + tags=("${minor_ver}-${stability_tag}") + if [[ -n "${LATEST_MAJOR}" ]]; then + tags+=("${major_ver}-${stability_tag}") + fi + else + if [[ -n "${LATEST}" ]]; then + tags+=("latest") + fi + fi - for tag in "${tags[@]}"; do - make release TAG="${tag}"; - done + for tag in "${tags[@]}"; do + make buildx-imagetools-create TAG=${tag} + done fi diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 2602220..352b9ea 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -11,13 +11,51 @@ on: env: DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} + MEMCACHED1: '1.6.37' jobs: - memcached-1: + memcached1-build: + strategy: + matrix: + platform: + - linux/amd64 + - linux/arm64 + include: + - platform: linux/amd64 + runner: ubuntu-24.04 + arch: amd64 + - platform: linux/arm64 + runner: ubuntu-24.04-arm + arch: arm64 + runs-on: ${{ matrix.runner }} + steps: + - uses: actions/checkout@v4 + - uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + - uses: docker/setup-buildx-action@v3 + - name: build and push + env: + MEMCACHED_VER: ${{ env.MEMCACHED1 }} + ARCH: ${{ matrix.arch }} + PLATFORM: ${{ matrix.platform }} + run: | + make buildx-build + make test + make buildx-push + memcached1-push: runs-on: ubuntu-latest + needs: + - memcached1-build steps: - - uses: actions/checkout@v2 - - uses: ./.github/actions - with: - version: '1.6.37' - tags: 1,latest + - uses: actions/checkout@v4 + - uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + - uses: ./.github/actions + with: + version: ${{ env.MEMCACHED1 }} + latest: true + latest_major: true diff --git a/Makefile b/Makefile index 4270a8d..9347bc3 100644 --- a/Makefile +++ b/Makefile @@ -2,18 +2,20 @@ MEMCACHED_VER ?= 1.6.37 -TAG ?= $(shell echo "${MEMCACHED_VER}" | grep -oE '^[0-9]+\.[0-9]+') +MEMCACHED_VER_MINOR ?= $(shell echo "${MEMCACHED_VER}" | grep -oE '^[0-9]+\.[0-9]+') + +TAG ?= $(MEMCACHED_VER_MINOR) REPO = wodby/memcached NAME = memcached-$(MEMCACHED_VER) -ifneq ($(STABILITY_TAG),) - ifneq ($(TAG),latest) - override TAG := $(TAG)-$(STABILITY_TAG) - endif +PLATFORM ?= linux/arm64 + +ifneq ($(ARCH),) + override TAG := $(TAG)-$(ARCH) endif -.PHONY: build test push shell run start stop logs clean release +.PHONY: build buildx-build buildx-imagetools-create buildx-push test push shell run start stop logs clean release default: build @@ -22,6 +24,23 @@ build: --build-arg MEMCACHED_VER=$(MEMCACHED_VER) \ ./ +buildx-build: + docker buildx build --platform $(PLATFORM) -t $(REPO):$(TAG) \ + --build-arg MEMCACHED_VER=$(MEMCACHED_VER) \ + --load \ + ./ + +buildx-push: + docker buildx build --platform $(PLATFORM) --push -t $(REPO):$(TAG) \ + --build-arg MEMCACHED_VER=$(MEMCACHED_VER) \ + ./ + +buildx-imagetools-create: + docker buildx imagetools create -t $(REPO):$(TAG) \ + $(REPO):$(MEMCACHED_VER_MINOR)-amd64 \ + $(REPO):$(MEMCACHED_VER_MINOR)-arm64 +.PHONY: buildx-imagetools-create + test: cd ./tests && IMAGE=$(REPO):$(TAG) NAME=$(NAME) ./run.sh diff --git a/README.md b/README.md index 7e0916c..9bc61f0 100755 --- a/README.md +++ b/README.md @@ -21,6 +21,8 @@ Supported tags and respective `Dockerfile` links: - `1`, `latest` [_(Dockerfile)_] +All images built for `linux/amd64` and `linux/arm64` + ## Orchestration Actions Usage: