2023-12-05 11:52:09 +00:00
|
|
|
on:
|
|
|
|
workflow_call:
|
|
|
|
inputs:
|
|
|
|
git-ref:
|
|
|
|
required: true
|
|
|
|
type: string
|
|
|
|
description: "The github ref to checkout for building the Docker images."
|
|
|
|
tag-prefix:
|
|
|
|
required: true
|
|
|
|
type: string
|
2024-01-22 17:51:49 +00:00
|
|
|
description: "The prefix of the Docker image tag. i.e. 'nightly' for 'surrealdb/surrealdb:nightly-dev'."
|
2023-12-05 11:52:09 +00:00
|
|
|
build:
|
|
|
|
required: false
|
|
|
|
type: boolean
|
|
|
|
default: true
|
|
|
|
description: "Build the Docker images."
|
|
|
|
push:
|
|
|
|
required: false
|
|
|
|
type: boolean
|
|
|
|
default: false
|
|
|
|
description: "Publish the Docker images."
|
|
|
|
latest:
|
|
|
|
required: false
|
|
|
|
type: boolean
|
|
|
|
default: false
|
|
|
|
description: "Update the latest tag of the Docker image."
|
|
|
|
secrets:
|
|
|
|
DOCKER_USER:
|
|
|
|
required: false
|
|
|
|
DOCKER_PASS:
|
|
|
|
required: false
|
|
|
|
|
|
|
|
defaults:
|
|
|
|
run:
|
|
|
|
shell: bash
|
|
|
|
|
|
|
|
jobs:
|
|
|
|
prepare:
|
|
|
|
name: Prepare steps
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
outputs:
|
|
|
|
tag-prefix: ${{ steps.tag-prefix.outputs.tag-prefix }}
|
2024-01-22 17:51:49 +00:00
|
|
|
matrix: ${{ steps.set-matrix.outputs.matrix }}
|
2023-12-05 11:52:09 +00:00
|
|
|
steps:
|
|
|
|
- name: Sanitize tag name
|
|
|
|
id: tag-prefix
|
|
|
|
run: |
|
|
|
|
echo "tag-prefix=$(echo '${{ inputs.tag-prefix }}' | sed 's/[^a-zA-Z0-9_.-]/-/g' | tr '[:upper:]' '[:lower:]')" >> $GITHUB_OUTPUT
|
2024-01-22 17:51:49 +00:00
|
|
|
|
2023-12-05 11:52:09 +00:00
|
|
|
# Define matrix here so we don't need to search for it when making changes
|
|
|
|
- name: Set matrix
|
|
|
|
id: set-matrix
|
|
|
|
env:
|
2024-01-22 17:51:49 +00:00
|
|
|
MATRIX: |
|
2023-12-05 11:52:09 +00:00
|
|
|
include:
|
2024-01-22 17:51:49 +00:00
|
|
|
# Prod image
|
2023-12-05 11:52:09 +00:00
|
|
|
- &base_image
|
2024-01-22 17:51:49 +00:00
|
|
|
name: Prod image
|
|
|
|
build-target: prod-ci
|
|
|
|
# Dev image
|
2023-12-05 11:52:09 +00:00
|
|
|
- <<: *base_image
|
2024-01-22 17:51:49 +00:00
|
|
|
name: Dev image
|
|
|
|
build-target: dev-ci
|
|
|
|
tag-suffix: -dev
|
2023-12-05 11:52:09 +00:00
|
|
|
|
|
|
|
run: |
|
2024-01-22 17:51:49 +00:00
|
|
|
echo '${{ env.MATRIX }}' > matrix.yaml
|
|
|
|
echo "matrix=$(yq -o json -I=0 matrix.yaml)" >> $GITHUB_OUTPUT
|
|
|
|
|
|
|
|
docker:
|
|
|
|
name: Build ${{ matrix.name }} (${{ matrix.build-target }})
|
|
|
|
runs-on: ubuntu-latest
|
2023-12-05 11:52:09 +00:00
|
|
|
needs: prepare
|
|
|
|
if: ${{ inputs.build }}
|
|
|
|
strategy:
|
|
|
|
fail-fast: false
|
2024-01-22 17:51:49 +00:00
|
|
|
matrix: ${{ fromJson(needs.prepare.outputs.matrix) }}
|
2023-12-05 11:52:09 +00:00
|
|
|
steps:
|
|
|
|
- name: Checkout
|
|
|
|
uses: actions/checkout@v4
|
2023-12-05 19:26:04 +00:00
|
|
|
|
2023-12-05 11:52:09 +00:00
|
|
|
- name: Set up Buildx
|
|
|
|
uses: docker/setup-buildx-action@v3
|
|
|
|
|
2024-01-22 17:51:49 +00:00
|
|
|
- name: Download artifacts
|
2024-03-18 09:29:19 +00:00
|
|
|
uses: actions/download-artifact@v4
|
2024-01-22 17:51:49 +00:00
|
|
|
with:
|
|
|
|
path: artifacts
|
|
|
|
|
|
|
|
- name: Build Docker image (amd64)
|
2023-12-05 11:52:09 +00:00
|
|
|
uses: docker/build-push-action@v5
|
2024-01-22 17:51:49 +00:00
|
|
|
id: build-amd64
|
2023-12-05 11:52:09 +00:00
|
|
|
with:
|
2024-01-22 17:51:49 +00:00
|
|
|
context: artifacts
|
2023-12-05 11:52:09 +00:00
|
|
|
load: true
|
2024-01-22 17:51:49 +00:00
|
|
|
platforms: linux/amd64
|
|
|
|
file: docker/Dockerfile
|
2023-12-05 11:52:09 +00:00
|
|
|
target: ${{ matrix.build-target }}
|
2024-01-22 17:51:49 +00:00
|
|
|
tags: surrealdb-local:amd64
|
|
|
|
build-args: |
|
|
|
|
ARTIFACT_PREFIX=surreal-${{ inputs.tag-prefix }}
|
2023-12-05 11:52:09 +00:00
|
|
|
|
2024-01-22 17:51:49 +00:00
|
|
|
- name: Build Docker image (arm64)
|
2023-12-05 11:52:09 +00:00
|
|
|
uses: docker/build-push-action@v5
|
2024-01-22 17:51:49 +00:00
|
|
|
id: build-arm64
|
2023-12-05 11:52:09 +00:00
|
|
|
with:
|
2024-01-22 17:51:49 +00:00
|
|
|
context: artifacts
|
|
|
|
load: true
|
|
|
|
platforms: linux/arm64
|
|
|
|
file: docker/Dockerfile
|
|
|
|
target: ${{ matrix.build-target }}
|
|
|
|
tags: surrealdb-local:arm64
|
2023-12-05 11:52:09 +00:00
|
|
|
build-args: |
|
2024-01-22 17:51:49 +00:00
|
|
|
ARTIFACT_PREFIX=surreal-${{ inputs.tag-prefix }}
|
2023-12-05 11:52:09 +00:00
|
|
|
|
2024-01-22 17:51:49 +00:00
|
|
|
- name: Test the Docker image
|
|
|
|
run: docker run --platform linux/amd64 --rm surrealdb-local:amd64 version
|
2023-12-05 11:52:09 +00:00
|
|
|
|
2024-01-23 14:49:03 +00:00
|
|
|
- name: Configure DockerHub
|
|
|
|
uses: docker/login-action@v3
|
|
|
|
if: ${{ inputs.push }}
|
|
|
|
with:
|
|
|
|
username: ${{ secrets.DOCKER_USER }}
|
|
|
|
password: ${{ secrets.DOCKER_PASS }}
|
|
|
|
|
2024-01-22 17:51:49 +00:00
|
|
|
- name: Push to DockerHub
|
2023-12-05 11:52:09 +00:00
|
|
|
uses: docker/build-push-action@v5
|
2024-01-22 17:51:49 +00:00
|
|
|
if: ${{ inputs.push }}
|
2023-12-05 11:52:09 +00:00
|
|
|
with:
|
2024-01-22 17:51:49 +00:00
|
|
|
context: artifacts
|
2023-12-05 11:52:09 +00:00
|
|
|
push: true
|
2024-01-22 17:51:49 +00:00
|
|
|
platforms: linux/amd64,linux/arm64
|
|
|
|
file: docker/Dockerfile
|
|
|
|
target: ${{ matrix.build-target }}
|
|
|
|
tags: surrealdb/surrealdb:${{ inputs.tag-prefix }}${{ matrix.tag-suffix }}
|
2023-12-05 11:52:09 +00:00
|
|
|
build-args: |
|
2024-01-22 17:51:49 +00:00
|
|
|
ARTIFACT_PREFIX=surreal-${{ inputs.tag-prefix }}
|
2023-12-05 11:52:09 +00:00
|
|
|
|
2024-01-22 17:51:49 +00:00
|
|
|
- name: Push to DockerHub (latest)
|
2023-12-05 11:52:09 +00:00
|
|
|
uses: docker/build-push-action@v5
|
2024-01-22 17:51:49 +00:00
|
|
|
if: ${{ inputs.push && inputs.latest }}
|
2023-12-05 11:52:09 +00:00
|
|
|
with:
|
2024-01-22 17:51:49 +00:00
|
|
|
context: artifacts
|
2023-12-05 11:52:09 +00:00
|
|
|
push: true
|
2024-01-22 17:51:49 +00:00
|
|
|
platforms: linux/amd64,linux/arm64
|
|
|
|
file: docker/Dockerfile
|
|
|
|
target: ${{ matrix.build-target }}
|
|
|
|
tags: surrealdb/surrealdb:latest${{ matrix.tag-suffix }}
|
2023-12-05 11:52:09 +00:00
|
|
|
build-args: |
|
2024-01-22 17:51:49 +00:00
|
|
|
ARTIFACT_PREFIX=surreal-${{ inputs.tag-prefix }}
|