Code development platform for open source projects from the European Union institutions :large_blue_circle: EU Login authentication by SMS has been phased out. To see alternatives please check here

Skip to content
Snippets Groups Projects
Commit 56c5eae2 authored by Raphael JOIE's avatar Raphael JOIE
Browse files

Merge branch 'ci' into 'main'

Ci

See merge request !3
parents 782be160 0e7c1550
No related branches found
No related tags found
1 merge request!3Ci
Pipeline #149265 failed
workflow:
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
when: never
# Don't run on first init commit of a branch
- if: $CI_COMMIT_BRANCH && $CI_COMMIT_BEFORE_SHA == "0000000000000000000000000000000000000000"
when: never
- if: $CI_COMMIT_BRANCH
stages:
- build
- deliver
build:
image: node:20
tags:
- docker
- lab
stage: build
script:
- npm install
- npm run build
artifacts:
paths:
- dist
build-gitlab-ci-docker:
stage: build
tags:
- lab
- shell
rules:
- changes:
- gitlab-ci/*.Dockerfile
when: always
- when: manual
parallel:
matrix:
- NMS_CI_JOB:
- gitlab-ci
variables:
IMAGE_TAG: $CI_REGISTRY/$CI_PROJECT_PATH/${NMS_CI_JOB}:latest
script:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
- docker build --build-arg http_proxy=${HTTP_PROXY} --build-arg https_proxy=${HTTPS_PROXY} -t ${IMAGE_TAG} --file gitlab-ci/${NMS_CI_JOB}.Dockerfile .
- docker push $IMAGE_TAG
needs:
- build
dependencies:
- build
deliver-umd:
image: node:20
tags:
- docker
- lab
stage: deliver
script:
- PACKAGE_VERSION=$(node -e "const c = require('./package.json'); console.log(c.version)")
- echo ${PACKAGE_VERSION}
- 'curl --header "JOB-TOKEN: $CI_JOB_TOKEN" --header "Content-Type: text/javascript" --upload-file dist/umd/index.js "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/umd/latest/index.js"'
- 'curl --header "JOB-TOKEN: $CI_JOB_TOKEN" --header "Content-Type: text/css" --upload-file dist/umd/assets/styles.css "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/umd/latest/styles.css"'
- 'curl --header "JOB-TOKEN: $CI_JOB_TOKEN" --header "Content-Type: text/javascript " --upload-file dist/umd/index.js "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/umd/${PACKAGE_VERSION}/index.js"'
- 'curl --header "JOB-TOKEN: $CI_JOB_TOKEN" --header "Content-Type: text/css" --upload-file dist/umd/assets/styles.css "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/umd/${PACKAGE_VERSION}/styles.css"'
needs:
- build
dependencies:
- build
deliver-package:
image: node:20
tags:
- docker
- lab
stage: deliver
script:
- echo "registry=https://${CI_SERVER_HOST}/api/v4/projects/${CI_PROJECT_ID}/packages/npm/" > .npmrc
- echo "//${CI_SERVER_HOST}/api/v4/projects/${CI_PROJECT_ID}/packages/npm/:_authToken=${CI_JOB_TOKEN}" >> .npmrc
- npm publish
needs:
- build
dependencies:
- build
......@@ -10,7 +10,7 @@ React is used under the hood but the goal is to produce a JS library in UMD form
<script crossorigin src="https://unpkg.com/react@18/umd/react.development.js"></script>
<script crossorigin src="https://unpkg.com/react-dom@18/umd/react-dom.development.js"></script>
<!-- library import -->
<script src="../../dist/umd/index.js"></script>
<script charset="UTF-8" type="text/javascript" src="https://code.europa.eu/api/v4/projects/digit-c4%2Fdev%2Fopenapi-browser/packages/generic/openapi-browser-landscape-viewer/latest/index.js"></script>
</head>
<body>
<div id="root"></div>
......@@ -39,3 +39,35 @@ npm run demo
npm run build
```
and open test/browser/index.htm in web browser
## Gitlab CI Pipelines
A few-lines Gitlab pipelines is provided as part of this repo to publish OpenAPI specs
in [Gitlab Pages](https://docs.gitlab.com/ee/user/project/pages/). This pipeline
will automatically search for OpenAPI specifications published in the Project registry
and publish a page to browse all version found
> For the pipeline to work, openapi `json` specifications must first be published
> as generic package
> ```yaml
> - publish-openapi-specs-generic-package-job:
> variables:
> VERSION: v0.1.0
> script:
> - 'curl --header "JOB-TOKEN: $CI_JOB_TOKEN" --upload-file build/openapi.json "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/openapi/${VERSION}/openapi.json"'
> ```
```yaml
include:
- project: 'digit-c4/dev/openapi-browser'
file: 'gitlab-ci/pages-job.yml'
ref: v0.1
stages:
- doc
# Job to generate pages must be named `pages`
pages:
stage: doc
tags:
- docker
```
#!/usr/bin/env python3
import json
import os
import requests
CI_API_V4_URL = os.getenv('CI_API_V4_URL')
CI_PROJECT_ID = os.getenv('CI_PROJECT_ID')
CI_JOB_TOKEN = os.getenv('CI_JOB_TOKEN')
r = requests.get(f"{CI_API_V4_URL}/projects/{CI_PROJECT_ID}/packages?package_name=openapi",
headers={"JOB-TOKEN": CI_JOB_TOKEN})
try:
r.raise_for_status()
except:
raise Exception("Unable to load OpenAPI packages from Gitlab project registry")
data = r.json()
os.makedirs("public", exist_ok=True)
versions = {}
for package in data:
version = package['version']
openapi = requests.get(f"{CI_API_V4_URL}/projects/{CI_PROJECT_ID}/packages/generic/openapi/{version}/openapi.json",
headers={"JOB-TOKEN": CI_JOB_TOKEN})
openapi.raise_for_status()
filename = f'{version}.openapi.json'
with open(f'public/{filename}', 'w') as f:
f.write(str(openapi.text))
versions[version] = filename
with open("public/versions.js", 'w') as f:
f.write(f"NMS_OPENAPI_VERSIONS = {str(json.dumps(versions))}")
FROM code.europa.eu:4567/digit-c4/dev/python-best-practices/python-poetry:3.11-alpine
RUN pip install requests
WORKDIR /usr/bin
COPY gitlab-ci/ci-script.py ci-script
RUN chmod +x ci-script
WORKDIR /openapi-browser
COPY dist/umd/index.js index.js
COPY dist/umd/assets/styles.css styles.css
COPY gitlab-ci/index.html index.html
<html>
<head>
<script crossorigin src="https://unpkg.com/react@18.2.0/umd/react.development.js"></script>
<script crossorigin src="https://unpkg.com/react-dom@18.2.0/umd/react-dom.development.js"></script>
<script charset="UTF-8" src="index.js"></script>
<script charset="UTF-8" src="versions.js"></script>
<link rel="stylesheet" type="text/css" href="styles.css">
</head>
<body>
<div id="root"></div>
<script>
OpenApiBrowser({
props: {
versions: NMS_OPENAPI_VERSIONS,
}
})
</script>
</body>
</html>
pages:
tags:
- docker
image: code.europa.eu:4567/digit-c4/dev/openapi-browser/gitlab-ci:latest
script:
- ci-script
- cp /openapi-browser/index.js public/index.js
- cp /openapi-browser/index.html public/index.html
- cp /openapi-browser/styles.css public/styles.css
artifacts:
paths:
- public
......@@ -4,12 +4,15 @@
<script crossorigin src="https://unpkg.com/react-dom@18.2.0/umd/react-dom.development.js"></script>
<script charset="UTF-8" src="../../dist/umd/index.js"></script>
<link rel="stylesheet" type="text/css" href="../../dist/umd/assets/styles.css">
<script charset="UTF-8" src="versions.js"></script>
</head>
<body>
<div id="root"></div>
<script>
OpenApiBrowser({
props: {}
props: {
versions: NMS_OPENAPI_VERSIONS,
}
})
</script>
</body>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment