Skip to content

Commit

Permalink
Selectively build docker image (#47)
Browse files Browse the repository at this point in the history
Only build image if docker file has been modified.

Closes #45
  • Loading branch information
arnfinn authored Feb 5, 2024
1 parent f9e8845 commit 5b957c7
Showing 1 changed file with 25 additions and 10 deletions.
35 changes: 25 additions & 10 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,44 @@ concurrency:
cancel-in-progress: true

jobs:
changes:
runs-on: ubuntu-latest
permissions:
pull-requests: read
outputs:
# Expose matched filters as job 'packages' output variable
images: ${{ steps.filter.outputs.changes }}
steps:
# For pull requests it's not necessary to checkout the code
- uses: dorny/paths-filter@v3
id: filter
with:
filters: |
code-server: "code-server/**"
rstudio: "rstudio/**"
base-r: "base-r/**"
dev: "dev/**"
push_to_registries:
needs: changes
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
config:
- {name: code-server}
- {name: rstudio}
- {name: base-r}
- {name: dev}
name: ${{ matrix.config.name }}
image: ${{ fromJSON(needs.changes.outputs.images) }}
name: ${{ matrix.image }}
steps:
- name: Check out the repo
uses: actions/[email protected]
- name: Lint Dockerfile
uses: hadolint/[email protected]
with:
dockerfile: "${{ matrix.config.name }}/Dockerfile"
dockerfile: "${{ matrix.image }}/Dockerfile"
- name: Prepare tags
id: docker_meta
uses: docker/[email protected]
with:
images: rapporteket/${{ matrix.config.name }}
images: rapporteket/${{ matrix.image }}
tags: |
type=ref,event=branch
type=ref,event=pr
Expand All @@ -55,8 +70,8 @@ jobs:
- name: Build and push to Docker Hub
uses: docker/[email protected]
with:
context: ./${{ matrix.config.name }}/.
file: ./${{ matrix.config.name }}/Dockerfile
context: ./${{ matrix.image }}/.
file: ./${{ matrix.image }}/Dockerfile
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.docker_meta.outputs.tags }}
labels: ${{ steps.docker_meta.outputs.labels }}
Expand Down

0 comments on commit 5b957c7

Please sign in to comment.