Skip to content
This repository has been archived by the owner on Jul 26, 2024. It is now read-only.

Commit

Permalink
global: fix Dockerfile and gh-actions
Browse files Browse the repository at this point in the history
  • Loading branch information
drjova committed Jul 16, 2024
1 parent 17387e9 commit 814a664
Show file tree
Hide file tree
Showing 8 changed files with 183 additions and 87 deletions.
52 changes: 52 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Build

on:
workflow_call:
inputs:
ref:
description: The reference to build
type: string
required: true
image:
description: The name of the image to build
type: string
required: true
context:
description: The context used to build the image
type: string
required: true
dockerfile:
description: The path to the Dockerfile
type: string
required: false
outputs:
image-id:
description: The ID of image that has been built
value: ${{ jobs.build.outputs.image-id }}

jobs:
build:
runs-on: ubuntu-latest
outputs:
image-id: ${{ steps.build.outputs.image-id }}
steps:
- name: Checkout Code
uses: actions/checkout@v4
with:
ref: ${{ inputs.ref }}

- id: build
name: Build and push
uses: cern-sis/gh-workflows/.github/actions/[email protected]
with:
image: ${{ inputs.image }}
context: ${{ inputs.context }}
dockerfile: ${{ inputs.dockerfile }}
registry: registry.cern.ch
cache: false
tags: |
type=ref,event=branch
type=ref,event=pr
type=ref,event=tag
username: ${{ secrets.HARBOR_USERNAME }}
password: ${{ secrets.HARBOR_PASSWORD }}
21 changes: 21 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Lint

on:
workflow_call:
inputs:
ref:
description: The reference to build
type: string
required: true

jobs:
linter:
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v4
with:
ref: ${{ inputs.ref }}

- name: Pre-commit check
uses: pre-commit/[email protected]
16 changes: 16 additions & 0 deletions .github/workflows/pull-request-main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Pull request main

on:
pull_request_target:
branches: [main]

jobs:
lint:
uses: ./.github/workflows/lint.yml
with:
ref: ${{ github.ref }}
test:
uses: ./.github/workflows/test.yml
with:
ref: ${{ github.event.pull_request.head.sha }}
secrets: inherit
31 changes: 31 additions & 0 deletions .github/workflows/push-main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Push main

on:
push:
branches: [main]

defaults:
run:
shell: bash

jobs:
lint:
uses: ./.github/workflows/lint.yml
with:
ref: ${{ github.ref }}
test:
uses: ./.github/workflows/test.yml
with:
ref: ${{ github.ref }}
secrets: inherit
deploy:
needs: [lint, test]
runs-on: ubuntu-latest
steps:
- name: send event
uses: cern-sis/gh-workflows/.github/actions/[email protected]
with:
event-type: update
images: |
cern-sis/inspire/workflows@${{ needs.test.outputs.image-id }}
token: ${{ secrets.PAT_FIRE_EVENTS_ON_CERN_SIS_KUBERNETES }}
59 changes: 59 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: Tests

on:
workflow_call:
inputs:
ref:
description: The reference to build
type: string
required: true
outputs:
image-id:
description: The ID of image that has been built
value: ${{ jobs.build.outputs.image-id }}

defaults:
run:
shell: bash

jobs:
build:
uses: ./.github/workflows/build.yml
with:
ref: ${{ inputs.ref }}
image: cern-sis/inspire/backoffice
context: .
dockerfile: ./compose/production/django/Dockerfile
secrets: inherit
test:
needs: build
runs-on: ubuntu-latest
services:
redis:
image: redis
ports:
- 6379:6379
postgres:
image: postgres:13
env:
POSTGRES_USER: airflow
POSTGRES_PASSWORD: airflow
POSTGRES_DB: airflow
ports:
- 5431:5431
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ inputs.ref }}

- name: Test
run: >
docker run
-v "$(pwd)"/tests:/opt/airflow/tests
-v "$(pwd)"/dags:/opt/airflow/dags
-v "$(pwd)"/airflow.cfg:/opt/airflow/airflow.cfg
-v "$(pwd)"/requirements-test.txt:/opt/airflow/requirements-test.txt
-v "$(pwd)"/data:/opt/airflow/data
${{ inputs.image }}
bash -c "pip install -r requirements-text.txt && airflow db init && pytest /opt/airflow/tests"
77 changes: 0 additions & 77 deletions .github/workflows/test_and_build.yml

This file was deleted.

12 changes: 3 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
FROM apache/airflow:2.8.3-python3.11

USER root
COPY --chown=airflow:root dags /opt/airflow/dags/
COPY --chown=airflow:root requirements.txt ./requirements.txt

RUN mkdir -p ${AIRFLOW_HOME} && chown -R airflow: ${AIRFLOW_HOME}

USER airflow

RUN airflow db init
COPY requirements.txt ./requirements.txt
COPY requirements-test.txt ./requirements-test.txt
RUN pip install --no-cache-dir --upgrade --user -r requirements.txt -r requirements-test.txt
RUN pip install --no-cache-dir "apache-airflow==${AIRFLOW_VERSION}" -r requirements.txt
2 changes: 1 addition & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ services:
start_period: 5s
restart: always
ports:
- 5431:5432
- 5431:5431

inspire-db:
image: postgres:13
Expand Down

0 comments on commit 814a664

Please sign in to comment.