Skip to content

Commit 5b87438

Browse files
committed
Build Docker Images Locally When Dockerfiles Change
1 parent 10629df commit 5b87438

File tree

15 files changed

+577
-379
lines changed

15 files changed

+577
-379
lines changed

.github/actions/docker-publish/action.yml

Lines changed: 0 additions & 61 deletions
This file was deleted.
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
name: 'Docker Skiko Publish'
2+
description: 'Build and optionally publish a Docker image to ghcr.io for skiko'
3+
4+
inputs:
5+
image_name:
6+
description: 'Image name (e.g., linux-compat)'
7+
required: true
8+
platforms:
9+
description: 'Target platforms (e.g., linux/amd64 or linux/amd64,linux/arm64). If not specified, uses runner architecture.'
10+
required: false
11+
tag:
12+
description: 'Image tag (e.g., latest)'
13+
required: true
14+
load:
15+
description: 'Whether to load the image into the local Docker daemon'
16+
required: false
17+
default: 'false'
18+
should_publish:
19+
description: 'Whether to push the image to the registry'
20+
required: true
21+
github_token:
22+
description: 'GitHub token for authentication (required only if should_publish is true)'
23+
required: false
24+
25+
runs:
26+
using: 'composite'
27+
steps:
28+
- name: 'Set Variables'
29+
id: vars
30+
shell: bash
31+
run: |
32+
echo "image_namespace=${GITHUB_REPOSITORY,,}" >> $GITHUB_OUTPUT
33+
34+
# Normalize tag: replace invalid docker tag characters
35+
TAG="${{ inputs.tag }}"
36+
TAG="${TAG//\//-}"
37+
echo "tag=${TAG}" >> $GITHUB_OUTPUT
38+
39+
- name: 'Set up Docker Buildx'
40+
uses: docker/setup-buildx-action@v3
41+
42+
- name: 'Log into registry'
43+
if: inputs.should_publish == 'true'
44+
uses: docker/login-action@v3
45+
with:
46+
registry: ghcr.io
47+
username: ${{ github.actor }}
48+
password: ${{ inputs.github_token }}
49+
50+
- name: 'Extract metadata'
51+
id: meta
52+
uses: docker/metadata-action@v5
53+
with:
54+
images: ghcr.io/${{ steps.vars.outputs.image_namespace }}/${{ inputs.image_name }}
55+
tags: |
56+
type=raw,value=${{ steps.vars.outputs.tag }}
57+
58+
- name: 'Build and push'
59+
uses: docker/build-push-action@v5
60+
with:
61+
context: ./skiko/docker/${{ inputs.image_name }}
62+
platforms: ${{ inputs.platforms }}
63+
push: ${{ inputs.should_publish == 'true' }}
64+
load: ${{ inputs.load == 'true' }}
65+
tags: ${{ steps.meta.outputs.tags }}
66+
labels: ${{ steps.meta.outputs.labels }}
67+
cache-from: type=gha
68+
cache-to: type=gha,mode=max
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
name: 'Docker Skiko Run'
2+
description: 'Build Docker image locally if needed and run commands inside it'
3+
4+
inputs:
5+
image_name:
6+
description: 'Image name (e.g., linux-compat)'
7+
required: true
8+
command:
9+
description: 'Command to run inside the container'
10+
required: true
11+
working_directory:
12+
description: 'Working directory relative to project root (e.g., samples/SkiaAndroidSample)'
13+
required: false
14+
default: '.'
15+
virtual-display:
16+
description: 'Enable virtual display for UI testing (enables e2e UI interaction tests with real windows)'
17+
required: false
18+
default: 'false'
19+
base_ref:
20+
description: 'Base ref/sha for change detection (defaults to auto-detect)'
21+
required: false
22+
default: ''
23+
24+
runs:
25+
using: 'composite'
26+
steps:
27+
- name: 'Detect Docker changes'
28+
id: filter
29+
uses: dorny/paths-filter@v3
30+
with:
31+
base: ${{ inputs.base_ref || github.event.pull_request.base.sha || github.event.before || 'master' }}
32+
filters: |
33+
docker_changed:
34+
- '.github/actions/docker-skiko-publish/**'
35+
- '.github/workflows/docker-publish.yml'
36+
- 'skiko/docker/${{ inputs.image_name }}/**'
37+
38+
- name: 'Set Variables'
39+
id: vars
40+
shell: bash
41+
run: |
42+
IMAGE_NAMESPACE="${GITHUB_REPOSITORY,,}"
43+
echo "image_namespace=${IMAGE_NAMESPACE}" >> $GITHUB_OUTPUT
44+
45+
# Determine which tag to use
46+
# github.base_ref is set for PRs regardless of event type (pull_request or workflow_call)
47+
if [[ -n "${{ github.base_ref }}" && "${{ steps.filter.outputs.docker_changed }}" != "true" ]]; then
48+
# For PRs without docker changes, use base branch tag (pre-built image)
49+
TAG="${{ github.base_ref }}"
50+
else
51+
# For PRs with docker changes or non-PRs, use current branch tag
52+
TAG="${GITHUB_REF_NAME}"
53+
fi
54+
TAG="${TAG//\//-}"
55+
56+
# Try to pull image from GHCR
57+
# This checks both if the image exists in the registry and loads it into the local daemon
58+
if docker pull "ghcr.io/${IMAGE_NAMESPACE}/${{ inputs.image_name }}:${TAG}" >/dev/null 2>&1; then
59+
IMAGE_EXISTS="true"
60+
else
61+
IMAGE_EXISTS="false"
62+
fi
63+
64+
echo "tag=${TAG}" >> $GITHUB_OUTPUT
65+
echo "image_exists=${IMAGE_EXISTS}" >> $GITHUB_OUTPUT
66+
67+
- name: 'Build Docker image locally (if needed)'
68+
if: steps.filter.outputs.docker_changed == 'true' || steps.vars.outputs.image_exists == 'false'
69+
uses: ./.github/actions/docker-skiko-publish
70+
with:
71+
image_name: ${{ inputs.image_name }}
72+
tag: ${{ steps.vars.outputs.tag }}
73+
load: true
74+
should_publish: false
75+
76+
- name: 'Prepare command'
77+
id: cmd
78+
shell: bash
79+
run: |
80+
CMD="${{ inputs.command }}"
81+
if [[ "${{ inputs.virtual-display }}" == "true" ]]; then
82+
CMD="Xvfb :1 -screen 0 1920x1080x24 -extension RANDR +extension GLX & export DISPLAY=:1.0 && ${CMD}"
83+
fi
84+
{
85+
echo "command<<EOF"
86+
echo "${CMD}"
87+
echo "EOF"
88+
} >> $GITHUB_OUTPUT
89+
90+
- name: 'Run command in container'
91+
shell: bash
92+
run: |
93+
docker run --rm \
94+
-v "${{ github.workspace }}":/workspace \
95+
-v "${HOME}/.gradle":/gradle-cache \
96+
-e GRADLE_USER_HOME=/gradle-cache \
97+
-w /workspace/${{ inputs.working_directory }} \
98+
"ghcr.io/${{ steps.vars.outputs.image_namespace }}/${{ inputs.image_name }}:${{ steps.vars.outputs.tag }}" \
99+
bash -c '${{ steps.cmd.outputs.command }}'

.github/actions/setup-prerequisites/action.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,19 @@
11
name: 'Setup Prerequisites'
2+
description: 'Shared steps to prepare build environment'
3+
24
runs:
35
using: "composite"
46
steps:
7+
- name: Free up space on GitHub runner
8+
if: runner.os == 'Linux'
9+
shell: bash
10+
run: |
11+
df -h
12+
sudo rm -rf /usr/share/dotnet
13+
sudo rm -rf /opt/ghc
14+
sudo rm -rf /opt/hostedtoolcache/CodeQL
15+
df -h
16+
517
- name: Setup Gradle
618
uses: gradle/actions/setup-gradle@v4
719
with:

0 commit comments

Comments
 (0)