Skip to content

Feat/first nib images #4

Feat/first nib images

Feat/first nib images #4

name: Docker Build Test
on:
pull_request:
branches: [ main ]
paths:
- '**/Dockerfile'
# Configure GITHUB_TOKEN permissions
permissions:
contents: read
packages: read
pull-requests: read
id-token: write
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
test-build:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- uses: actions/checkout@v4
- name: Generate build matrix
id: set-matrix
run: |
DIRS=$(find . -name Dockerfile -exec dirname {} \; | sed 's|^\./||' | jq -R -s -c 'split("\n")[:-1]')
echo "matrix=${DIRS}" >> $GITHUB_OUTPUT
build-test:
needs: test-build
runs-on: ubuntu-latest
strategy:
matrix:
image_path: ${{ fromJson(needs.test-build.outputs.matrix) }}
steps:
- uses: actions/checkout@v4
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Generate version
id: version
run: |
if [[ "${{ matrix.image_path }}" == clients/* ]]; then
IMAGE_NAME="blockjoy-$(basename ${{ matrix.image_path }})"
if [[ -f "${{ matrix.image_path }}/Dockerfile" ]]; then
CLIENT_VERSION=$(grep -E "ENV.*_VERSION=[[:space:]]*v?[0-9]+\.[0-9]+\.[0-9]+[-.a-zA-Z0-9]*" "${{ matrix.image_path }}/Dockerfile" | grep -oE "v?[0-9]+\.[0-9]+\.[0-9]+[-.a-zA-Z0-9]*")
if [[ ! -z "$CLIENT_VERSION" ]]; then
CLIENT_VERSION=${CLIENT_VERSION#v}
IMAGE_TAG="${CLIENT_VERSION}-$(git rev-parse --short HEAD)"
else
IMAGE_TAG="$(git rev-parse --short HEAD)"
fi
else
IMAGE_TAG="$(git rev-parse --short HEAD)"
fi
else
IMAGE_NAME=$(echo ${{ matrix.image_path }} | tr '/' '-')
IMAGE_TAG="$(git rev-parse --short HEAD)"
fi
echo "image_name=${IMAGE_NAME}" >> $GITHUB_OUTPUT
echo "image_tag=${IMAGE_TAG}" >> $GITHUB_OUTPUT
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Test build image
uses: docker/build-push-action@v5
with:
context: ./${{ matrix.image_path }}
push: false
load: true
build-args: |
${{ startsWith(matrix.image_path, 'node-base') && format('GRAFANA_LOKI_API_KEY={0}
GRAFANA_PROM_API_KEY={1}', secrets.GRAFANA_LOKI_API_KEY, secrets.GRAFANA_PROM_API_KEY) || '' }}
${{ startsWith(matrix.image_path, 'clients') && format('GRAFANA_LOKI_BASICAUTH={0}
GRAFANA_PROM_BASICAUTH={1}
CLOUDFLARE_API_KEY={2}', secrets.GRAFANA_LOKI_BASICAUTH, secrets.GRAFANA_PROM_BASICAUTH, secrets.CLOUDFLARE_API_KEY) || '' }}
cache-from: type=gha
cache-to: type=gha,mode=max
tags: ghcr.io/blockjoy/${{ steps.version.outputs.image_name }}:${{ steps.version.outputs.image_tag }}