Skip to content
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

Pipeline refactor/Better control when the docker image is built #450

Closed
wants to merge 13 commits into from
51 changes: 9 additions & 42 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
name: check
on: [push]
on:
workflow_call:
inputs:
test-image:
required: true
type: string
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}/e2e
BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
jobs:
lint:
Expand All @@ -17,46 +20,10 @@ jobs:
- run: npx eslint .
working-directory: react

build-and-push-image:
runs-on: ubuntu-22.04
outputs:
image_tag: ${{ steps.meta.outputs.tags }}
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: .
file: react/test/Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=registry,ref=${{ steps.meta.outputs.tags }}
cache-to: type=inline

build-frontend:
runs-on: ubuntu-22.04
needs: build-and-push-image
container:
image: ghcr.io/${{ needs.build-and-push-image.outputs.image_tag }}
image: ${{ inputs.test-image }}
steps:
- uses: actions/checkout@v4
- run: python3 create_website.py react/test/density-db --no-data --no-geo --no-juxta
Expand All @@ -77,9 +44,9 @@ jobs:

run-e2e-tests:
runs-on: ubuntu-22.04
needs: [build-and-push-image, build-frontend, list-e2e-tests]
needs: [build-frontend, list-e2e-tests]
container:
image: ghcr.io/${{ needs.build-and-push-image.outputs.image_tag }}
image: ${{ inputs.test-image }}
strategy:
fail-fast: false
matrix:
Expand Down
75 changes: 75 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
name: main
on:
pull_request:
push:
branches:
- master
jobs:
check-dockerfile-changes:
runs-on: ubuntu-22.04
outputs:
changed: ${{ steps.get-changed-files.outputs.any_changed }}
steps:
- uses: actions/checkout@v4
- id: get-changed-files
uses: tj-actions/changed-files@v45
with:
files: |
react/test/Dockerfile

build-and-push-image:
runs-on: ubuntu-22.04
needs: check-dockerfile-changes
if: needs.check-dockerfile-changes.outputs.changed == 'true'
outputs:
image_tag: ${{ steps.meta.outputs.tags }}
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ github.repository }}/e2e

- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: .
file: react/test/Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=registry,ref=${{ steps.meta.outputs.tags }}
cache-to: type=inline

run-checks-built-image:
needs: build-and-push-image
uses: ./.github/workflows/check.yml
with:
test-image: ghcr.io/${{ needs.build-and-push-image.outputs.image_tag }}

run-checks-main-image:
needs: check-dockerfile-changes
if: needs.check-dockerfile-changes.outputs.changed == 'false' && github.event_name == 'push'
uses: ./.github/workflows/check.yml
with:
test-image: ghcr.io/${{ github.repository }}/e2e:${{ github.event.repository.default_branch }}

run-checks-base-image:
needs: check-dockerfile-changes
if: needs.check-dockerfile-changes.outputs.changed == 'false' && github.event_name == 'pull_request'
uses: ./.github/workflows/check.yml
with:
test-image: ghcr.io/${{ github.repository }}/e2e:${{ github.event.pull_request.base.ref }}
2 changes: 1 addition & 1 deletion react/test/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ RUN dpkg --add-architecture i386
RUN apt-get -y update
RUN apt-get -y install libgdal-dev

RUN apt-get -y install chromium
RUN apt-get -y install chromium=130.*
RUN apt-get -y install xvfb

RUN apt-get -y install sqlite3
Expand Down
Loading