Skip to content

Commit

Permalink
gh-actions: update deploy (#75)
Browse files Browse the repository at this point in the history
  • Loading branch information
drjova committed Jun 28, 2023
1 parent 1cf88f5 commit 6211229
Showing 1 changed file with 62 additions and 78 deletions.
140 changes: 62 additions & 78 deletions .github/workflows/test-and-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,18 @@ on:
pull_request_target:
branches: [master]

env:
REGISTRY: registry.cern.ch
IMAGE_UI: cern-sis/cat-ui
IMAGE_BACKEND: cern-sis/cat-backend
IMAGE_HARVEST: cern-sis/cat-harvest

jobs:
backend_build_test:
name: Backend Build and Test
runs-on: ubuntu-latest
env:
BACKEND_IMAGE: registry.cern.ch/cern-sis/cat-backend:${{ github.sha }}
outputs:
image_backend: ${{ steps.build.outputs.image-digest }}
defaults:
run:
working-directory: backend
Expand All @@ -36,61 +42,58 @@ jobs:
POSTGRES_DB: cat
ports:
- 5432:5432

steps:
- name: Checkout
uses: actions/checkout@v2
with:
python-version: ${{ matrix.python-version }}

- name: Build Image
uses: cern-sis/gh-workflows/.github/actions/build-docker@v1.0.0
id: build
uses: cern-sis/gh-workflows/.github/actions/docker-build@v6
with:
registry: ${{ env.REGISTRY }}
image: ${{ env.IMAGE_BACKEND }}
cache: false
context: ./backend/
tags: registry.cern.ch/cern-sis/cat-backend:${{ github.sha }}

- name: Run tests
run: |
docker run --network=host --name=cat-backend --entrypoint poetry $BACKEND_IMAGE run python manage.py test
- name: Push to Registry
if: ${{ github.event_name == 'push' }}
uses: ./.github/actions/push
with:
registry: registry.cern.ch
username: ${{ secrets.HARBOR_USERNAME }}
password: ${{ secrets.HARBOR_PASSWORD }}
image: registry.cern.ch/cern-sis/cat-backend:${{ github.sha }}

- name: Run tests
run: >
docker run
--network=host
--name=cat-backend
--entrypoint poetry
$REGISTRY/$IMAGE@${{ steps.build.outputs.image-digest }}
run python manage.py test
ui_build_test:
name: UI Build and Test
runs-on: ubuntu-latest
env:
UI_IMAGE: registry.cern.ch/cern-sis/cat-ui:${{ github.sha }}
outputs:
image_ui: ${{ steps.build.outputs.image-digest }}
defaults:
run:
working-directory: ui
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Build Image
uses: cern-sis/gh-workflows/.github/actions/build-docker@v1.0.0
id: build
uses: cern-sis/gh-workflows/.github/actions/docker-build@v6
with:
registry: ${{ env.REGISTRY }}
image: ${{ env.IMAGE_UI }}
cache: false
context: ./ui/
tags: registry.cern.ch/cern-sis/cat-ui:${{ github.sha }}

- name: Push to Registry
if: ${{ github.event_name == 'push' }}
uses: ./.github/actions/push
with:
registry: registry.cern.ch
username: ${{ secrets.HARBOR_USERNAME }}
password: ${{ secrets.HARBOR_PASSWORD }}
image: registry.cern.ch/cern-sis/cat-ui:${{ github.sha }}

harvest_build_test:
name: Harvest Build and Test
runs-on: ubuntu-latest
env:
HARVEST_IMAGE: registry.cern.ch/cern-sis/cat-harvest:${{ github.sha }}
outputs:
image_harvest: ${{ steps.build.outputs.image-digest }}
defaults:
run:
working-directory: harvest
Expand All @@ -102,56 +105,37 @@ jobs:
uses: actions/checkout@v2
with:
python-version: ${{ matrix.python-version }}

- name: Build Image
uses: cern-sis/gh-workflows/.github/actions/build-docker@v1.0.0
id: build
uses: cern-sis/gh-workflows/.github/actions/docker-build@v6
with:
registry: ${{ env.REGISTRY }}
image: ${{ env.IMAGE_HARVEST }}
cache: false
context: ./harvest/
tags: registry.cern.ch/cern-sis/cat-harvest:${{ github.sha }}

- name: Run tests
run: |
docker run --network=host --name=cat-harvest --entrypoint poetry $HARVEST_IMAGE run pytest tests
- name: Push to Registry
if: ${{ github.event_name == 'push' }}
uses: ./.github/actions/push
with:
registry: registry.cern.ch
username: ${{ secrets.HARBOR_USERNAME }}
password: ${{ secrets.HARBOR_PASSWORD }}
image: registry.cern.ch/cern-sis/cat-harvest:${{ github.sha }}

Deploy_Backend:
needs: [backend_build_test]
uses: cern-sis/gh-workflows/.github/workflows/deploy-qa.yml@v1.0.0
with:
project: cat
application: cat-backend
namespace: cat-qa
image: registry.cern.ch/cern-sis/cat-backend
secrets:
PAT: ${{ secrets.PAT_FIRE_EVENTS_ON_CERN_SIS_KUBERNETES }}

Deploy_UI:
needs: [ui_build_test]
uses: cern-sis/gh-workflows/.github/workflows/deploy-qa.yml@v1.0.0
with:
project: cat
application: cat-ui
namespace: cat-qa
image: registry.cern.ch/cern-sis/cat-ui
secrets:
PAT: ${{ secrets.PAT_FIRE_EVENTS_ON_CERN_SIS_KUBERNETES }}

Deploy_Harvest:
needs: [harvest_build_test]
uses: cern-sis/gh-workflows/.github/workflows/deploy-qa.yml@v1.0.0
with:
project: cat
application: cat-harvest
namespace: cat-qa
image: registry.cern.ch/cern-sis/cat-harvest
secrets:
PAT: ${{ secrets.PAT_FIRE_EVENTS_ON_CERN_SIS_KUBERNETES }}

- name: Run tests
run: >
docker run
--network=host
--name=cat-harvest
--entrypoint poetry
$REGISTRY/$IMAGE@${{ steps.build.outputs.image-digest }}
run pytest tests
push_to_QA:
name: Push to QA
runs-on: ubuntu-latest
needs: [backend_build_test, ui_build_test, harvest_build_test]
steps:
- name: send event
uses: cern-sis/gh-workflows/.github/actions/kubernetes-project-new-images@v6
with:
event-type: update
images: |
${{needs.backend_build_test.outputs.image_backend}}
${{needs.ui_build_test.outputs.image_ui}}
${{needs.harvest_build_test.outputs.image_harvest}}
token: ${{ secrets.PAT_FIRE_EVENTS_ON_CERN_SIS_KUBERNETES }}

0 comments on commit 6211229

Please sign in to comment.