Skip to content

Commit

Permalink
add matrix
Browse files Browse the repository at this point in the history
  • Loading branch information
peaceiris committed Jun 1, 2024
1 parent bbc5b1a commit edcee3e
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 43 deletions.
37 changes: 26 additions & 11 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,25 @@ concurrency:
group: ${{ github.workflow }}-${{ github.ref }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

env:
IS_PULL_REQUEST: ${{ github.event_name == 'pull_request' }}

jobs:
hadolint:
uses: peaceiris/workflows/.github/workflows/hadolint.yml@v0.20.1

docker:
runs-on: namespace-profile-ubuntu2204-amd64-8x16-with-cache
timeout-minutes: ${{ github.event_name == 'pull_request' && 15 || 30 }}
runs-on: ${{ matrix.runner }}
timeout-minutes: ${{ github.event_name == 'pull_request' && 5 || 10 }}
permissions:
actions: write
contents: read
packages: write
strategy:
fail-fast: true
matrix:
runner:
- namespace-profile-ubuntu2204-amd64-8x16-with-cache
- namespace-profile-ubuntu2204-arm64-8x16-with-cache
steps:
- uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6

Expand All @@ -36,15 +44,22 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
DOCKER_HUB_TOKEN: ${{ secrets.DOCKER_HUB_TOKEN }}

# - run: make setup-buildx
- run: make build
- run: make test

# - uses: peaceiris/actions-export-envs@v1.1.0
# id: envs
merge:
needs: docker
runs-on: ubuntu-22.04
timeout-minutes: 5
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6

- run: make build
- run: make login
env:
# ACTIONS_RUNTIME_TOKEN: ${{ steps.envs.outputs.ACTIONS_RUNTIME_TOKEN }}
# ACTIONS_CACHE_URL: ${{ steps.envs.outputs.ACTIONS_CACHE_URL }}
DOCKER_MULTI_PLATFORM: ${{ github.event_name == 'pull_request' && 'false' || 'true' }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
DOCKER_HUB_TOKEN: ${{ secrets.DOCKER_HUB_TOKEN }}

- run: make test
- run: make merge
65 changes: 33 additions & 32 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,24 @@ DOCKER_TAG := v${DOCKER_VERSION}
GITHUB_REF_NAME ?= local
DOCKER_SCOPE := mdbook-${GITHUB_REF_NAME}
DOCKER_OUTPUT_TYPE ?= docker
ifeq (${DOCKER_MULTI_PLATFORM}, true)
DOCKER_PLATFORM := --platform linux/amd64,linux/arm64
DOCKER_DRY_RUN ?= --dry-run
ifeq ($(IS_PULL_REQUEST), false)
DOCKER_OUTPUT_TYPE := registry
DOCKER_DRY_RUN :=
endif
PKG_NAME := ${DOCKER_BASE_NAME}:${DOCKER_TAG}
HUB_NAME := ${DOCKER_HUB_BASE_NAME}:${DOCKER_TAG}
PKG_NAME_LATEST := ${DOCKER_BASE_NAME}:latest
HUB_NAME_LATEST := ${DOCKER_HUB_BASE_NAME}:latest
PKG_LATEST := ${DOCKER_BASE_NAME}:latest
HUB_LATEST := ${DOCKER_HUB_BASE_NAME}:latest

ARCH := $(shell uname -m)
ifeq ($(ARCH), x86_64)
PLATFORM := amd64
CARGO_TARGET := x86_64-unknown-linux-musl
else ifeq ($(ARCH), arm64)
PLATFORM := arm64
CARGO_TARGET := aarch64-unknown-linux-musl
endif

.PHONY: login-dockerhub
login-dockerhub:
Expand All @@ -44,50 +54,41 @@ build: build-alpine build-rust
.PHONY: build-alpine
build-alpine:
docker buildx build . \
--tag "${PKG_NAME}" \
--tag "${HUB_NAME}" \
--tag "${PKG_NAME_LATEST}" \
--tag "${HUB_NAME_LATEST}" \
${DOCKER_PLATFORM} \
--annotation "index,manifest,index-descriptor,manifest-descriptor:org.opencontainers.image.authors=peaceiris (Shohei Ueda)" \
--annotation "index,manifest,index-descriptor,manifest-descriptor:org.opencontainers.image.url=https://github.com/peaceiris/docker-mdbook" \
--annotation "index,manifest,index-descriptor,manifest-descriptor:org.opencontainers.image.documentation=https://github.com/peaceiris/docker-mdbook/blob/main/README.md" \
--annotation "index,manifest,index-descriptor,manifest-descriptor:org.opencontainers.image.source=https://github.com/peaceiris/docker-mdbook/blob/main/Dockerfile" \
--annotation "index,manifest,index-descriptor,manifest-descriptor:org.opencontainers.image.description=Alpine-based Docker Images for mdBook" \
--annotation "index,manifest,index-descriptor,manifest-descriptor:org.opencontainers.image.licenses=MIT" \
--annotation "index,manifest,index-descriptor,manifest-descriptor:org.opencontainers.image.version=${DOCKER_TAG}" \
--tag "${HUB_NAME}-$(PLATFORM)" \
--output "type=${DOCKER_OUTPUT_TYPE}" \
--cache-from "type=gha,scope=${DOCKER_SCOPE}" \
--cache-to "type=gha,mode=max,scope=${DOCKER_SCOPE}" \
--build-arg MDBOOK_VERSION="${DOCKER_VERSION}" \
--build-arg BASE_IMAGE="alpine:3.20" \
--build-arg MDBOOK_MERMAID_VERSION="${MDBOOK_MERMAID_VERSION}" \
--build-arg MDBOOK_TOC_VERSION="${MDBOOK_TOC_VERSION}"
--build-arg MDBOOK_TOC_VERSION="${MDBOOK_TOC_VERSION}" \
--build-arg CARGO_TARGET="${CARGO_TARGET}"

.PHONY: build-rust
build-rust:
docker buildx build . \
--tag "${PKG_NAME}-rust" \
--tag "${HUB_NAME}-rust" \
--tag "${PKG_NAME_LATEST}-rust" \
--tag "${HUB_NAME_LATEST}-rust" \
${DOCKER_PLATFORM} \
--annotation "index,manifest,index-descriptor,manifest-descriptor:org.opencontainers.image.authors=peaceiris (Shohei Ueda)" \
--annotation "index,manifest,index-descriptor,manifest-descriptor:org.opencontainers.image.url=https://github.com/peaceiris/docker-mdbook" \
--annotation "index,manifest,index-descriptor,manifest-descriptor:org.opencontainers.image.documentation=https://github.com/peaceiris/docker-mdbook/blob/main/README.md" \
--annotation "index,manifest,index-descriptor,manifest-descriptor:org.opencontainers.image.source=https://github.com/peaceiris/docker-mdbook/blob/main/Dockerfile" \
--annotation "index,manifest,index-descriptor,manifest-descriptor:org.opencontainers.image.description=Alpine-based Docker Images for mdBook" \
--annotation "index,manifest,index-descriptor,manifest-descriptor:org.opencontainers.image.licenses=MIT" \
--annotation "index,manifest,index-descriptor,manifest-descriptor:org.opencontainers.image.version=${DOCKER_TAG}-rust" \
--tag "${HUB_NAME}-rust-$(PLATFORM)" \
--output "type=${DOCKER_OUTPUT_TYPE}" \
--cache-from "type=gha,scope=${DOCKER_SCOPE}" \
--cache-to "type=gha,mode=max,scope=${DOCKER_SCOPE}" \
--build-arg MDBOOK_VERSION="${DOCKER_VERSION}" \
--build-arg BASE_IMAGE="rust:1.78-alpine3.20" \
--build-arg MDBOOK_MERMAID_VERSION="${MDBOOK_MERMAID_VERSION}" \
--build-arg MDBOOK_TOC_VERSION="${MDBOOK_TOC_VERSION}"
--build-arg MDBOOK_TOC_VERSION="${MDBOOK_TOC_VERSION}" \
--build-arg CARGO_TARGET="${CARGO_TARGET}"

.PHONY: test
test:
@docker run --rm "${HUB_NAME}" --version
@docker run --rm "${HUB_NAME}-rust" --version
@docker run --rm "${HUB_NAME}-$(PLATFORM)" --version
@docker run --rm "${HUB_NAME}-rust-$(PLATFORM)" --version

.PHONY: merge
merge:
docker buildx imagetools create ${DOCKER_DRY_RUN} --tag "${PKG_NAME}" "${HUB_NAME}-amd64" "${HUB_NAME}-arm64"
docker buildx imagetools create ${DOCKER_DRY_RUN} --tag "${HUB_NAME}" "${HUB_NAME}-amd64" "${HUB_NAME}-arm64"
docker buildx imagetools create ${DOCKER_DRY_RUN} --tag "${PKG_LATEST}" "${HUB_NAME}-amd64" "${HUB_NAME}-arm64"
docker buildx imagetools create ${DOCKER_DRY_RUN} --tag "${HUB_LATEST}" "${HUB_NAME}-amd64" "${HUB_NAME}-arm64"
docker buildx imagetools create ${DOCKER_DRY_RUN} --tag "${PKG_NAME}-rust" "${HUB_NAME}-rust-amd64" "${HUB_NAME}-rust-arm64"
docker buildx imagetools create ${DOCKER_DRY_RUN} --tag "${HUB_NAME}-rust" "${HUB_NAME}-rust-amd64" "${HUB_NAME}-rust-arm64"
docker buildx imagetools create ${DOCKER_DRY_RUN} --tag "${PKG_LATEST}-rust" "${HUB_NAME}-rust-amd64" "${HUB_NAME}-rust-arm64"
docker buildx imagetools create ${DOCKER_DRY_RUN} --tag "${HUB_LATEST}-rust" "${HUB_NAME}-rust-amd64" "${HUB_NAME}-rust-arm64"

0 comments on commit edcee3e

Please sign in to comment.