Skip to content

Commit

Permalink
chore: setup reusable workflows (#83)
Browse files Browse the repository at this point in the history
* chore: setup reusable workflows, use new organization-catalog path

Co-authored-by: NilsOveTen <github.nils.ove@tendenes.com>
  • Loading branch information
valosnah and NilsOveTen authored Apr 5, 2022
1 parent 9930a86 commit c7b8009
Show file tree
Hide file tree
Showing 11 changed files with 75 additions and 245 deletions.
49 changes: 0 additions & 49 deletions .github/workflows/deploy-demo.yaml

This file was deleted.

43 changes: 43 additions & 0 deletions .github/workflows/deploy-prod&demo.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Deploy to production & demo

on:
push:
branches:
- main
workflow_dispatch:

jobs:
build-and-deploy-production:
name: Deploy to prod on merge to main branch
uses: Informasjonsforvaltning/workflows/.github/workflows/build-deploy-nox.yaml@main
with:
app_name: dcat-ap-no-validator-service
caller_sha: ${{ github.sha }}
repo: ${{ github.repository }}
actor: ${{ github.actor }}
python_version: '3.9'
python_architecture: x64
environment: prod
cluster: digdir-fdk-prod
nox_image: True
secrets:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GCP_SA_DIGDIR_FDK_GCR_KEY: ${{ secrets.GCP_SA_DIGDIR_FDK_GCR_KEY }}
DIGDIR_FDK_AUTODEPLOY: ${{ secrets.DIGDIR_FDK_PROD_AUTODEPLOY }}
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}

deploy-to-demo:
needs: build-and-deploy-production
name: Deploy to demo if prod-deploy is successful
uses: Informasjonsforvaltning/workflows/.github/workflows/deploy.yaml@main
with:
app_name: dcat-ap-no-validator-service
caller_sha: ${{ github.sha }}
repo: ${{ github.repository }}
actor: ${{ github.actor }}
environment: demo
cluster: digdir-fdk-dev
secrets:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
DIGDIR_FDK_AUTODEPLOY: ${{ secrets.DIGDIR_FDK_DEV_AUTODEPLOY }}
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
100 changes: 0 additions & 100 deletions .github/workflows/deploy-prod.yaml

This file was deleted.

100 changes: 18 additions & 82 deletions .github/workflows/deploy-staging.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,86 +7,22 @@ on:
- main

jobs:
build-and-deploy:
name: Build, test and deploy to staging environment
runs-on: ubuntu-latest
build-and-deploy-staging:
name: Call reusable workflow when pull request is created
if: github.event.pull_request.draft == false

steps:
- name: Checkout
uses: actions/checkout@v2

- name: Auth gcloud CLI for image-store
uses: google-github-actions/auth@main
with:
credentials_json: ${{ secrets.GCP_SA_DIGDIR_FDK_GCR_KEY }}

- name: Configure docker to use the gcloud command-line tool as a credential helper
run: gcloud auth configure-docker eu.gcr.io

- name: Cache Docker layers
uses: actions/cache@v2
with:
path: .cache
key: ${{ runner.os }}-nox-${{ github.sha }}
restore-keys: |
${{ runner.os }}-nox-
- name: Set up Python 3.9
uses: actions/setup-python@v1
with:
python-version: 3.9
architecture: x64

- name: Install dependencies
run: |
pip install --constraint=.github/workflows/constraints.txt pip
pipx install --pip-args=--constraint=.github/workflows/constraints.txt poetry
pipx install --pip-args=--constraint=.github/workflows/constraints.txt nox
pipx inject --pip-args=--constraint=.github/workflows/constraints.txt nox nox-poetry
- name: Build image and test with nox
run: nox

- name: Tag and publish docker image to Google Cloud
run: |
docker tag eu.gcr.io/digdir-fdk-infra/dcat-ap-no-validator-service:test eu.gcr.io/digdir-fdk-infra/dcat-ap-no-validator-service:$GITHUB_SHA
docker tag eu.gcr.io/digdir-fdk-infra/dcat-ap-no-validator-service:test eu.gcr.io/digdir-fdk-infra/dcat-ap-no-validator-service:staging_latest
docker rmi eu.gcr.io/digdir-fdk-infra/dcat-ap-no-validator-service:test
docker -- push eu.gcr.io/digdir-fdk-infra/dcat-ap-no-validator-service -a
- name: Apply Helm template
run: |
helm repo add fdk https://informasjonsforvaltning.github.io/helm-chart/
helm fetch --untar --untardir ./helm fdk/dcat-ap-no-validator-service
helm template --set DOCKER_IMAGE_NAME="eu.gcr.io/digdir-fdk-infra/dcat-ap-no-validator-service:$GITHUB_SHA" \
-f ./helm/dcat-ap-no-validator-service/values/staging.yaml \
./helm/dcat-ap-no-validator-service/ > ./kubectlapply.yaml
chmod o+w ./kubectlapply.yaml
cat kubectlapply.yaml
- name: Auth gcloud CLI for deploy
uses: google-github-actions/auth@main
with:
credentials_json: ${{ secrets.DIGDIR_FDK_DEV_AUTODEPLOY }}

- name: Deploy to GCP
run: |
gcloud container clusters get-credentials digdir-fdk-dev --region europe-north1-a --project digdir-fdk-dev
kubectl apply -f ./kubectlapply.yaml --force
if ! kubectl --namespace=staging rollout status deployment dcat-ap-no-validator-service; then
kubectl --namespace=staging rollout undo deployment dcat-ap-no-validator-service
kubectl --namespace=staging rollout status deployment dcat-ap-no-validator-service
exit 1
fi
- name: Notify slack
uses: 8398a7/action-slack@v3
with:
status: ${{ job.status }}
author_name: "Application: dcat-ap-no-validator-service | Environment: staging"
fields: commit,author,workflow
env:
GITHUB_TOKEN: ${{ github.token }}
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
if: always()
uses: Informasjonsforvaltning/workflows/.github/workflows/build-deploy-nox.yaml@main
with:
app_name: dcat-ap-no-validator-service
caller_sha: ${{ github.sha }}
repo: ${{ github.repository }}
actor: ${{ github.actor }}
python_version: '3.9'
python_architecture: x64
environment: staging
cluster: digdir-fdk-dev
nox_image: True
secrets:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GCP_SA_DIGDIR_FDK_GCR_KEY: ${{ secrets.GCP_SA_DIGDIR_FDK_GCR_KEY }}
DIGDIR_FDK_AUTODEPLOY: ${{ secrets.DIGDIR_FDK_DEV_AUTODEPLOY }}
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
2 changes: 1 addition & 1 deletion tests/files/mock_org-status.ttl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@prefix : <https://raw.githubusercontent.com/Informasjonsforvaltning/organization-catalogue/master/src/main/resources/ontology/org-status.ttl#> .
@prefix : <https://raw.githubusercontent.com/Informasjonsforvaltning/organization-catalog/master/src/main/resources/ontology/org-status.ttl#> .
@prefix skos: <http://www.w3.org/2004/02/skos/core#> .
@prefix skosno: <https://data.norge.no/vocabulary/skosno#> .
@prefix dct: <http://purl.org/dc/terms/> .
Expand Down
2 changes: 1 addition & 1 deletion tests/files/mock_org-types.ttl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@prefix : <https://raw.githubusercontent.com/Informasjonsforvaltning/organization-catalogue/master/src/main/resources/ontology/org-type.ttl#> .
@prefix : <https://raw.githubusercontent.com/Informasjonsforvaltning/organization-catalog/master/src/main/resources/ontology/org-type.ttl#> .
@prefix skos: <http://www.w3.org/2004/02/skos/core#> .
@prefix skosno: <https://data.norge.no/vocabulary/skosno#> .
@prefix dct: <http://purl.org/dc/terms/> .
Expand Down
6 changes: 3 additions & 3 deletions tests/files/mock_organization_catalogue_961181399.ttl
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
@prefix br: <https://raw.githubusercontent.com/Informasjonsforvaltning/organization-catalogue/master/src/main/resources/ontology/organization-catalogue.owl#> .
@prefix br: <https://raw.githubusercontent.com/Informasjonsforvaltning/organization-catalog/master/src/main/resources/ontology/organization-catalogue.owl#> .
@prefix dct: <http://purl.org/dc/terms/> .
@prefix adms: <http://www.w3.org/ns/adms#> .
@prefix org: <http://www.w3.org/ns/org#> .
@prefix rov: <http://www.w3.org/ns/regorg#> .
@prefix skos: <http://www.w3.org/2004/02/skos/core#> .
@prefix brskos: <https://raw.githubusercontent.com/Informasjonsforvaltning/organization-catalogue/master/src/main/resources/ontology/org-status.ttl#> .
@prefix brtype: <https://raw.githubusercontent.com/Informasjonsforvaltning/organization-catalogue/master/src/main/resources/ontology/org-type.ttl#> .
@prefix brskos: <https://raw.githubusercontent.com/Informasjonsforvaltning/organization-catalog/master/src/main/resources/ontology/org-status.ttl#> .
@prefix brtype: <https://raw.githubusercontent.com/Informasjonsforvaltning/organization-catalog/master/src/main/resources/ontology/org-type.ttl#> .
@prefix foaf: <http://xmlns.com/foaf/0.1/> .

<https://organization-catalog.fellesdatakatalog.digdir.no/organizations/961181399>
Expand Down
6 changes: 3 additions & 3 deletions tests/files/mock_organization_catalogue_991825827.ttl
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
@prefix br: <https://raw.githubusercontent.com/Informasjonsforvaltning/organization-catalogue/master/src/main/resources/ontology/organization-catalogue.owl#> .
@prefix br: <https://raw.githubusercontent.com/Informasjonsforvaltning/organization-catalog/master/src/main/resources/ontology/organization-catalogue.owl#> .
@prefix dct: <http://purl.org/dc/terms/> .
@prefix adms: <http://www.w3.org/ns/adms#> .
@prefix org: <http://www.w3.org/ns/org#> .
@prefix rov: <http://www.w3.org/ns/regorg#> .
@prefix skos: <http://www.w3.org/2004/02/skos/core#> .
@prefix brskos: <https://raw.githubusercontent.com/Informasjonsforvaltning/organization-catalogue/master/src/main/resources/ontology/org-status.ttl#> .
@prefix brtype: <https://raw.githubusercontent.com/Informasjonsforvaltning/organization-catalogue/master/src/main/resources/ontology/org-type.ttl#> .
@prefix brskos: <https://raw.githubusercontent.com/Informasjonsforvaltning/organization-catalog/master/src/main/resources/ontology/org-status.ttl#> .
@prefix brtype: <https://raw.githubusercontent.com/Informasjonsforvaltning/organization-catalog/master/src/main/resources/ontology/org-type.ttl#> .
@prefix foaf: <http://xmlns.com/foaf/0.1/> .

<https://organization-catalog.fellesdatakatalog.digdir.no/organizations/991825827>
Expand Down
4 changes: 2 additions & 2 deletions tests/files/ontologies.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
rdf:type owl:Ontology ;
owl:imports <https://www.w3.org/ns/regorg> ;
owl:imports <https://www.w3.org/ns/org> ;
owl:imports <https://raw.githubusercontent.com/Informasjonsforvaltning/organization-catalogue/master/src/main/resources/ontology/org-status.ttl> ;
owl:imports <https://raw.githubusercontent.com/Informasjonsforvaltning/organization-catalogue/master/src/main/resources/ontology/org-type.ttl> ;
owl:imports <https://raw.githubusercontent.com/Informasjonsforvaltning/organization-catalog/master/src/main/resources/ontology/org-status.ttl> ;
owl:imports <https://raw.githubusercontent.com/Informasjonsforvaltning/organization-catalog/master/src/main/resources/ontology/org-type.ttl> ;
.


Expand Down
4 changes: 2 additions & 2 deletions tests/files/skos_ontologies.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
rdf:type owl:Ontology ;
owl:imports <https://data.norge.no/vocabulary/skosno> ;
owl:imports <https://www.w3.org/ns/regorg> ;
owl:imports <https://raw.githubusercontent.com/Informasjonsforvaltning/organization-catalogue/master/src/main/resources/ontology/org-type.ttl> ;
owl:imports <https://raw.githubusercontent.com/Informasjonsforvaltning/organization-catalogue/master/src/main/resources/ontology/org-status.ttl> ;
owl:imports <https://raw.githubusercontent.com/Informasjonsforvaltning/organization-catalog/master/src/main/resources/ontology/org-type.ttl> ;
owl:imports <https://raw.githubusercontent.com/Informasjonsforvaltning/organization-catalog/master/src/main/resources/ontology/org-status.ttl> ;
owl:imports <http://www.w3.org/2006/vcard/ns> ;
.
4 changes: 2 additions & 2 deletions tests/integration/test_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,13 @@ def mocks(mock_aioresponse: Any, mocker: MockFixture) -> Any:
with open("tests/files/mock_org-status.ttl", "r") as file:
org_status = file.read()
mock_aioresponse.get(
"https://raw.githubusercontent.com/Informasjonsforvaltning/organization-catalogue/master/src/main/resources/ontology/org-status.ttl", # noqa
"https://raw.githubusercontent.com/Informasjonsforvaltning/organization-catalog/master/src/main/resources/ontology/org-status.ttl", # noqa
body=org_status,
)
with open("tests/files/mock_org-types.ttl", "r") as file:
org_types = file.read()
mock_aioresponse.get(
"https://raw.githubusercontent.com/Informasjonsforvaltning/organization-catalogue/master/src/main/resources/ontology/org-type.ttl", # noqa
"https://raw.githubusercontent.com/Informasjonsforvaltning/organization-catalog/master/src/main/resources/ontology/org-type.ttl", # noqa
body=org_types,
)
with open(
Expand Down

0 comments on commit c7b8009

Please sign in to comment.