Skip to content

Improve build times by caching layers, when possible #44

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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 33 additions & 2 deletions .github/workflows/build-and-push-containers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ name: Build and push containers
on:
release:
types: [published]
pull_request:

jobs:
release-container:
runs-on: ubuntu-latest
env:
DOCKER_USER: ${{ secrets.CONTAINER_USERNAME }}
steps:
- name: Compile tag list
id: tags
Expand All @@ -28,17 +31,45 @@ jobs:
uses: docker/setup-buildx-action@v1

- name: Login to GitHub Container Registry
if: ${{ env.DOCKER_USER }}
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ secrets.CONTAINER_USERNAME }}
username: ${{ env.DOCKER_USER }}
password: ${{ secrets.CONTAINER_PAT }}

- name: Build and push
- name: Build and push for release
if: ${{ github.event_name == 'release' }}
uses: docker/build-push-action@v2
with:
context: .
file: ./Dockerfile
platforms: linux/amd64
pull: true
push: true
tags: ${{ join(fromJSON(steps.tags.outputs.tags), ',') }}
cache-from: type=registry,ref=ghcr.io/laminas/laminas-continuous-integration-action:build-cache
cache-to: type=registry,ref=ghcr.io/laminas/laminas-continuous-integration-action:build-cache,mode=max

- name: Build for local pull request
if: ${{ github.event_name == 'pull_request' && env.DOCKER_USER }}
uses: docker/build-push-action@v2
with:
context: .
file: ./Dockerfile
platforms: linux/amd64
pull: true
push: false
cache-from: type=registry,ref=ghcr.io/laminas/laminas-continuous-integration-action:build-cache
cache-to: type=registry,ref=ghcr.io/laminas/laminas-continuous-integration-action:build-cache,mode=max

- name: Build for fork pull request
if: ${{ github.event_name == 'pull_request' && ! env.DOCKER_USER }}
uses: docker/build-push-action@v2
with:
context: .
file: ./Dockerfile
platforms: linux/amd64
pull: true
push: false
cache-from: type=registry,ref=ghcr.io/laminas/laminas-continuous-integration-action:build-cache
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -248,3 +248,19 @@ The container provides the following tools:
- A `yamllint` binary, via the [adrienverge/yamllint](https://github.com/adrienverge/yamllint) package.

- The [jq](https://stedolan.github.io/jq/) command, a CLI JSON processor.

## Notes on contributing

This package includes a workflow that will build the container during pull request, to verify that builds complete successfully.

The workflow has three different conditional build steps:

- One that happens only on release; this is irrelevant to pull requests.
- Two that happen for pull requests:
- One that triggers if the repository's `CONTAINER_USERNAME` (and, by extension, `CONTAINER_PAT`) secret is present.
- One that triggers if the repository's `CONTAINER_USERNAME` (and, by extension, `CONTAINER_PAT`) secret is NOT present.

In the case where the repository secrets are present, the build will also cache layers it has built, which will speed up later builds.
However, because repository secrets are not provided when a pull request is performed from a forked repository, the second case will kick in; in that scenario, the build will still run, but no layers will be pushed to the container registry.

As such, if you are a Laminas Technical Steering Committee member or a maintainer with write access to this repository, please submit your patches via branches pushed directly to the repository, as this will speed up builds for everyone.