-
Notifications
You must be signed in to change notification settings - Fork 170
Build Docker images locally when Dockerfiles change
#1161
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| name: 'Docker Skiko Publish' | ||
| description: 'Build and optionally publish a Docker image to ghcr.io for skiko' | ||
|
|
||
| inputs: | ||
| image_name: | ||
| description: 'Image name (e.g., linux-compat)' | ||
| required: true | ||
| platforms: | ||
| description: 'Target platforms (e.g., linux/amd64 or linux/amd64,linux/arm64). If not specified, uses runner architecture.' | ||
| required: false | ||
| tag: | ||
| description: 'Image tag (e.g., latest)' | ||
| required: true | ||
| load: | ||
| description: 'Whether to load the image into the local Docker daemon' | ||
| required: false | ||
| default: 'false' | ||
| should_publish: | ||
| description: 'Whether to push the image to the registry' | ||
| required: true | ||
| github_token: | ||
| description: 'GitHub token for authentication (required only if should_publish is true)' | ||
| required: false | ||
|
|
||
| runs: | ||
| using: 'composite' | ||
| steps: | ||
| - name: 'Set Variables' | ||
| id: vars | ||
| shell: bash | ||
| run: | | ||
| echo "image_namespace=${GITHUB_REPOSITORY,,}" >> $GITHUB_OUTPUT | ||
|
|
||
| # Normalize tag: replace invalid docker tag characters | ||
| TAG="${{ inputs.tag }}" | ||
| TAG="${TAG//\//-}" | ||
| echo "tag=${TAG}" >> $GITHUB_OUTPUT | ||
|
|
||
| - name: 'Set up Docker Buildx' | ||
| uses: docker/setup-buildx-action@v3 | ||
|
|
||
| - name: 'Log into registry' | ||
| if: inputs.should_publish == 'true' | ||
| uses: docker/login-action@v3 | ||
| with: | ||
| registry: ghcr.io | ||
| username: ${{ github.actor }} | ||
| password: ${{ inputs.github_token }} | ||
|
|
||
| - name: 'Extract metadata' | ||
| id: meta | ||
| uses: docker/metadata-action@v5 | ||
| with: | ||
| images: ghcr.io/${{ steps.vars.outputs.image_namespace }}/${{ inputs.image_name }} | ||
| tags: | | ||
| type=raw,value=${{ steps.vars.outputs.tag }} | ||
|
|
||
| - name: 'Build and push' | ||
| uses: docker/build-push-action@v5 | ||
| with: | ||
| context: ./skiko/docker/${{ inputs.image_name }} | ||
| platforms: ${{ inputs.platforms }} | ||
| push: ${{ inputs.should_publish == 'true' }} | ||
| load: ${{ inputs.load == 'true' }} | ||
| tags: ${{ steps.meta.outputs.tags }} | ||
| labels: ${{ steps.meta.outputs.labels }} | ||
| cache-from: type=gha | ||
| cache-to: type=gha,mode=max | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| name: 'Docker Skiko Run' | ||
igordmn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| description: 'Build Docker image locally if needed and run commands inside it' | ||
|
|
||
| inputs: | ||
| image_name: | ||
| description: 'Image name (e.g., linux-compat)' | ||
| required: true | ||
| command: | ||
| description: 'Command to run inside the container' | ||
| required: true | ||
| working_directory: | ||
| description: 'Working directory relative to project root (e.g., samples/SkiaAndroidSample)' | ||
| required: false | ||
| default: '.' | ||
| virtual-display: | ||
| description: 'Enable virtual display for UI testing (enables e2e UI interaction tests with real windows)' | ||
| required: false | ||
| default: 'false' | ||
| base_ref: | ||
| description: 'Base ref/sha for change detection (defaults to auto-detect)' | ||
| required: false | ||
| default: '' | ||
|
|
||
| runs: | ||
| using: 'composite' | ||
| steps: | ||
| - name: 'Detect Docker changes' | ||
| id: filter | ||
| uses: dorny/paths-filter@v3 | ||
| with: | ||
| base: ${{ inputs.base_ref || github.event.pull_request.base.sha || github.event.before || 'master' }} | ||
| filters: | | ||
| docker_changed: | ||
| - '.github/actions/docker-skiko-publish/**' | ||
| - '.github/workflows/docker-publish.yml' | ||
| - 'skiko/docker/${{ inputs.image_name }}/**' | ||
MatkovIvan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| - name: 'Set Variables' | ||
| id: vars | ||
| shell: bash | ||
| run: | | ||
| IMAGE_NAMESPACE="${GITHUB_REPOSITORY,,}" | ||
| echo "image_namespace=${IMAGE_NAMESPACE}" >> $GITHUB_OUTPUT | ||
|
|
||
| # Determine which tag to use | ||
| # github.base_ref is set for PRs regardless of event type (pull_request or workflow_call) | ||
| if [[ -n "${{ github.base_ref }}" && "${{ steps.filter.outputs.docker_changed }}" != "true" ]]; then | ||
| # For PRs without docker changes, use base branch tag (pre-built image) | ||
MatkovIvan marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| TAG="${{ github.base_ref }}" | ||
| else | ||
| # For PRs with docker changes or non-PRs, use current branch tag | ||
MatkovIvan marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| TAG="${GITHUB_REF_NAME}" | ||
| fi | ||
MatkovIvan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| TAG="${TAG//\//-}" | ||
|
|
||
| # Try to pull image from GHCR | ||
| # This checks both if the image exists in the registry and loads it into the local daemon | ||
| if docker pull "ghcr.io/${IMAGE_NAMESPACE}/${{ inputs.image_name }}:${TAG}" >/dev/null 2>&1; then | ||
| IMAGE_EXISTS="true" | ||
| else | ||
| IMAGE_EXISTS="false" | ||
| fi | ||
|
|
||
| echo "tag=${TAG}" >> $GITHUB_OUTPUT | ||
| echo "image_exists=${IMAGE_EXISTS}" >> $GITHUB_OUTPUT | ||
|
|
||
| - name: 'Build Docker image locally (if needed)' | ||
| if: steps.filter.outputs.docker_changed == 'true' || steps.vars.outputs.image_exists == 'false' | ||
igordmn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| uses: ./.github/actions/docker-skiko-publish | ||
MatkovIvan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| with: | ||
| image_name: ${{ inputs.image_name }} | ||
| tag: ${{ steps.vars.outputs.tag }} | ||
| load: true | ||
| should_publish: false | ||
|
|
||
| - name: 'Prepare command' | ||
| id: cmd | ||
| shell: bash | ||
| run: | | ||
| CMD="${{ inputs.command }}" | ||
| if [[ "${{ inputs.virtual-display }}" == "true" ]]; then | ||
| CMD="Xvfb :1 -screen 0 1920x1080x24 -extension RANDR +extension GLX & export DISPLAY=:1.0 && ${CMD}" | ||
| fi | ||
| { | ||
| echo "command<<EOF" | ||
| echo "${CMD}" | ||
| echo "EOF" | ||
| } >> $GITHUB_OUTPUT | ||
|
|
||
| - name: 'Run command in container' | ||
| shell: bash | ||
| run: | | ||
| docker run --rm \ | ||
| -v "${{ github.workspace }}":/workspace \ | ||
MatkovIvan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| -v "${HOME}/.gradle":/gradle-cache \ | ||
| -e GRADLE_USER_HOME=/gradle-cache \ | ||
| -w /workspace/${{ inputs.working_directory }} \ | ||
| "ghcr.io/${{ steps.vars.outputs.image_namespace }}/${{ inputs.image_name }}:${{ steps.vars.outputs.tag }}" \ | ||
| bash -c '${{ steps.cmd.outputs.command }}' | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.