-
-
Notifications
You must be signed in to change notification settings - Fork 20
Simplify docker build and push workflow #76
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,65 +11,43 @@ jobs: | |
env: | ||
DOCKER_USER: ${{ secrets.CONTAINER_USERNAME }} | ||
steps: | ||
- name: Compile tag list | ||
id: tags | ||
run: | | ||
TAG=${GITHUB_REF/refs\/tags\//} | ||
PREFIX=ghcr.io/laminas/laminas-continuous-integration | ||
MAJOR="${PREFIX}:$(echo ${TAG} | cut -d. -f1)" | ||
MINOR="${MAJOR}.$(echo ${TAG} | cut -d. -f2)" | ||
PATCH="${PREFIX}:${TAG}" | ||
echo "::set-output name=tags::[\"${MAJOR}\",\"${MINOR}\",\"${PATCH}\"]" | ||
|
||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
|
||
- name: Setup QEMU | ||
uses: docker/setup-qemu-action@v1 | ||
|
||
- name: Setup Docker Buildx | ||
uses: docker/setup-buildx-action@v1 | ||
with: | ||
install: true | ||
|
||
- name: Login to GitHub Container Registry | ||
if: ${{ env.DOCKER_USER }} | ||
if: ${{ github.event_name == 'release' }} | ||
uses: docker/login-action@v1 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ env.DOCKER_USER }} | ||
password: ${{ secrets.CONTAINER_PAT }} | ||
|
||
- 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 | ||
username: ${{ github.repository_owner }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Build for local pull request | ||
if: ${{ github.event_name == 'pull_request' && env.DOCKER_USER }} | ||
uses: docker/build-push-action@v2 | ||
- name: Docker meta | ||
id: docker_meta | ||
uses: docker/metadata-action@v3 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Given that for us, That would remove he need for this third-party to be involved. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
It have sanity checks and validations in place. Action that was used here failed immediately when used with ref for PR. |
||
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 }} | ||
images: ghcr.io/laminas/laminas-continuous-integration | ||
tags: | | ||
type=semver,pattern={{version}} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Checking the docs, https://github.com/docker/metadata-action#typepep440 seems to be more connected There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. semver is correct. |
||
type=ref,event=branch | ||
type=ref,event=pr | ||
flavor: | | ||
latest=false | ||
|
||
- name: Build image. Push for release | ||
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 | ||
push: ${{ github.event_name == 'release' }} | ||
tags: | | ||
${{ steps.docker_meta.outputs.tags }} | ||
labels: ${{ steps.docker_meta.outputs.labels }} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this fetched from the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, those are populated from action context, you can see output in log for metadata step:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
cache-from: type=gha | ||
cache-to: type=gha,mode=max |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actions token works for GHCR because package has this repository added with write access for actions.
Link for reference for TSC members: https://github.com/orgs/laminas/packages/container/laminas-continuous-integration/settings