Skip to content
Commits on Source (13)
extends:
- '@commitlint/config-conventional'
rules:
body-max-line-length: [2, 'always', 120]
footer-max-line-length: [2, 'always', 120]
header-max-length: [2, 'always', 72]
......@@ -10,13 +10,13 @@ include:
file: /templates/Runners/apps.education-docker.yaml
- project: EOLE/infra/ci-tools
ref: stable
file: /templates/Lint/Commitlint.yaml
file: /templates/Git.yaml
- project: EOLE/infra/ci-tools
ref: stable
file: /templates/Docker.yaml
file: /templates/Semantic-release.yaml
- project: EOLE/infra/ci-tools
ref: stable
file: /templates/Release/Semantic-release.yaml
file: /templates/Docker.yaml
stages:
- initial-checks
......@@ -33,10 +33,20 @@ variables:
# Override default `commitlint` stage
commitlint:
stage: initial-checks
extends: .git:commitlint
# Verify python code with black
# Make sure the test run before creating a new release and
# on `dev` branch after `merge-to-dev` job.
python:black:
stage: initial-checks
rules:
- !reference [.rules-map, not-on-schedule]
- !reference [.rules-map, not-on-draft]
- !reference [.rules-map, not-on-tag]
- !reference [.rules-map, on-dev]
- !reference [.rules-map, not-on-semantic-release-commit]
- !reference [.rules-map, on-branch]
image: "${PYTHON_BLACK_IMAGE}"
variables:
PYTHON_BLACK_IMAGE: "hub.eole.education/proxyhub/pyfound/black:latest_release"
......@@ -49,35 +59,34 @@ python:black:
###############################################################################
# The name of the built image is define globally by `$IMAGE_NAME`
build-docker:
extends: .build-docker-image
extends: .docker:image:build
rules:
- !reference [.rules-map, not-on-schedule]
- !reference [.rules-map, not-on-draft]
- !reference [.rules-map, on-release-tag]
- !reference [.rules-map, on-testing-tag]
- !reference [.rules-map, on-dev]
- !reference [.rules-map, not-on-semantic-release-commit]
- !reference [.rules-map, on-branch]
###############################################################################
# `release` stage: `semantic-release`, `tag *`
# `release` stage: `new release`, testing prerelease`, `merge-to-dev`, `tag *`
###############################################################################
# the `semantic-release` job is defined in `templates/Release/Semantic-Release.yaml`
# Avoid regression by merging all pre-release fixes to dev
merge-to-dev:
stage: release
extends: .on-release-tag
# We use whatever image that has git
image: 'hub.eole.education/eole/commitlint:latest'
script:
# Add `upstream` remote to push with `write_repository` token
# Use `${GITLAB_TOKEN}` for write permission
- "git remote show upstream 2> /dev/null || git remote add upstream ${CI_REPOSITORY_URL/${CI_JOB_TOKEN}/${GITLAB_TOKEN}}"
- 'git fetch --all'
- 'git checkout -b ${DEV_BRANCH} upstream/${DEV_BRANCH}'
- 'git merge --no-edit ${CI_COMMIT_TAG}'
- 'git push upstream ${DEV_BRANCH}'
# Remove `upstream` to avoid caching `CI_JOB_TOKEN`
- "git remote remove upstream"
# Create the release versions on `$STABLE_BRANCH`
new release: {extends: '.semantic-release:stable'}
# Create the prereleases versions on `$TESTING_BRANCH`
# update `.releaserc.js` variable `betaBranch`
testing prerelease: {extends: '.semantic-release:testing'}
# Avoid regression and update `version` of package*.json in `$DEV_BRANCH`
merge-to-dev: {extends: '.git:merge-to', variables: {GIT_MERGE_TARGET: $DEV_BRANCH}}
## tag contribution branches with a more stable name than `git-${CI_COMMIT_SHORT_SHA}`
tag contrib branch:
extends:
- .tag-docker-image
- .docker:image:tag
- .on-branches
variables:
# `feature/foo-bar_quux` → `feature-foo-bar-quux`
......@@ -85,54 +94,49 @@ tag contrib branch:
## dev images
tag dev:
extends:
- .tag-docker-image
- .on-dev
extends: .docker:image:tag
rules:
- !reference [.rules-map, not-on-schedule]
- !reference [.rules-map, not-on-draft]
- !reference [.rules-map, on-dev]
variables:
IMAGE_TAG: dev
## testing images
tag testing prerelease:
extends:
- .docker:image:tag
- .on-testing-tag
tag testing:
extends:
- .tag-docker-image
- .on-testing
- .docker:image:tag
- .on-testing-tag
variables:
IMAGE_TAG: testing
## stable images
# we retag the latest `testing`
.tag-stable:
extends: .tag-docker-image
variables:
SOURCE_TAG: "testing"
# add the `X.Y.Z` tag
tag release:
extends: .tag-stable
extends: .docker:image:tag
# add the `X` tag
tag major:
extends: .tag-stable
extends: .docker:image:tag
before_script:
- export RELEASE_PREFIX=${RELEASE_PREFIX:-release/}
- export RELEASE=${CI_COMMIT_TAG#${RELEASE_PREFIX}}
- export RELEASE=${CI_COMMIT_TAG#${RELEASE_TAG_PREFIX}}
- export IMAGE_TAG=${RELEASE%%.*}
# add the `X.Y` tag
tag minor:
extends:
- .tag-stable
extends: .docker:image:tag
before_script:
- export RELEASE_PREFIX=${RELEASE_PREFIX:-release/}
- export RELEASE=${CI_COMMIT_TAG#${RELEASE_PREFIX}}
- export RELEASE=${CI_COMMIT_TAG#${RELEASE_TAG_PREFIX}}
- export IMAGE_TAG=${RELEASE%.${RELEASE##*.}}
tag stable:
extends: .tag-stable
extends: .docker:image:tag
variables:
IMAGE_TAG: stable
tag latest:
extends: .tag-stable
extends: .docker:image:tag
variables:
IMAGE_TAG: latest
// Build the configuration depending of the environnement
// When using prerelease branches, we don't want changelog to be generated
// See https://github.com/semantic-release/changelog/issues/51#issuecomment-682609394
// Gitlab reference name
const branch = process.env.CI_COMMIT_REF_NAME;
const gitAssets = [];
// Configure your branches names
const stableBranch = 'master';
// Assign a branch name to produce a `beta` prerelease tag
const betaBranch = 'testing';
// Assign a branch name to produce a `alpha` prerelease tag
const alphaBranch = undefined;
// Assign a branch name to produce a `dev` prerelease tag
const devBranch = undefined;
// Configure semantic-release plugins
const breakingKeywords = ["BREAKING CHANGE", "BREAKING-CHANGE", "BREAKING CHANGES", "BREAKING-CHANGES"];
const changelogFile = 'docs/CHANGELOG.md';
// const chartDir = './chart';
// Configure `conventionalcommits`
// See:
// - https://github.com/conventional-changelog/conventional-changelog/issues/838
// - https://github.com/conventional-changelog/conventional-changelog/issues/317
// - https://github.com/conventional-changelog/conventional-changelog/pull/421
const commitTypes = [
{type: "build", section: "Build System", hidden: false},
{type: "chore", section: "Maintenance", hidden: true},
{type: "ci", section: "Continuous Integration", hidden: false},
{type: "docs", section: "Documentation", hidden: false},
{type: "feat", section: "Features", hidden: false},
{type: "fix", section: "Bug Fixes", hidden: false},
{type: "perf", section: "Performance Improvements", hidden: false},
{type: "refactor", section: "Code Refactoring", hidden: false},
{type: "revert", section: "Reverts", hidden: false},
{type: "style", section: "Styles", hidden: false},
{type: "test", section: "Tests", hidden: false},
];
const releaseRules = [
{ breaking: true, release: 'major' },
// { type: 'build', release: 'patch'},
// { type: 'chore', release: 'patch'},
// { type: 'ci', release: 'patch'},
{ type: 'docs', release: 'patch' },
{ type: 'feat', release: 'minor' },
{ type: 'fix', release: 'patch' },
{ type: 'perf', release: 'patch' },
{ type: 'refactor', release: 'patch' },
{ type: 'revert', release: 'patch' },
{ type: 'style', release: 'patch' },
{ type: 'test', release: 'patch' },
];
const semanticBranches = [stableBranch];
if (betaBranch) {
semanticBranches.push({
name: betaBranch,
prerelease: true
});
}
if (alphaBranch) {
semanticBranches.push({
name: alphaBranch,
prerelease: true
});
}
if (devBranch) {
semanticBranches.push({
name: devBranch,
prerelease: true
});
}
const config = {
branches: semanticBranches,
/* eslint no-template-curly-in-string: "off" */
tagFormat: 'release/${version}',
plugins: [
[
'@semantic-release/commit-analyzer',
{
preset: 'conventionalcommits',
parserOpts:
{
noteKeywords: breakingKeywords,
},
releaseRules: releaseRules,
presetConfig:
{
types: commitTypes,
},
},
],
[
'@semantic-release/release-notes-generator',
{
preset: 'conventionalcommits',
parserOpts:
{
noteKeywords: breakingKeywords,
},
presetConfig:
{
types: commitTypes,
},
},
],
],
};
if (
!Array.isArray(config.branches) ||
config.branches.some((it) => it === branch || (it.name === branch && !it.prerelease))
) {
// Generate changelog for release branch
config.plugins.push([
'@semantic-release/changelog',
{
changelogFile: changelogFile,
changelogTitle: '# Changelog',
},
]);
gitAssets.push(changelogFile);
}
// Commit changes and create release on Gitlab
config.plugins.push(
[
'@semantic-release/git',
{
assets: gitAssets,
message: 'chore(release): ${nextRelease.version}\n\n${nextRelease.notes}',
},
],
'@semantic-release/gitlab',
);
module.exports = config;
......@@ -4,10 +4,11 @@
from flask import jsonify
from flask_restful import Resource
import datetime
from init import mongo
from init import mongo, require_appkey
class User(Resource):
@require_appkey
def get(self, name):
datas = mongo.db.users.find({"username": name})
return self.formatUsersResult(datas)
......
......@@ -3,11 +3,12 @@
from flask import request, jsonify, json
from flask_restful import Resource
from init import mongo, app
import copy
from init import mongo, app, require_appkey
class Users(Resource):
@require_appkey
def get(self):
# users?search=searchstring&exact=1&keys=["email"]
searchstring = request.args.get("search")
......
module.exports = {
extends: ['@commitlint/config-conventional'],
rules: {
'body-max-line-length': [2, 'always', 120],
'footer-max-line-length': [2, 'always', 120],
'header-max-length': [2, 'always', 72],
},
};
# Changelog
## [1.1.0](https://gitlab.mim-libre.fr/alphabet/lookup-server/compare/release/1.0.0...release/1.1.0) (2023-11-07)
### Features
* **apikey:** secure access with LOOKUP_SERVER_API_KEY ([49efa64](https://gitlab.mim-libre.fr/alphabet/lookup-server/commit/49efa649b34e744166faa0cde0f8747b8b96f2b6))
### Continuous Integration
* **build-docker:** make sure build pass to create a release ([c648d1a](https://gitlab.mim-libre.fr/alphabet/lookup-server/commit/c648d1a975e921a3bc8acc343f8d52c35e099b19))
* **commitlint:** use new standard job `.git:commitlint` ([f88c78d](https://gitlab.mim-libre.fr/alphabet/lookup-server/commit/f88c78dfd71a8ceef5112199369eea1357ce93ce))
* **merge-to-dev:** use new standard jobs `.git:merge-to` ([f8246af](https://gitlab.mim-libre.fr/alphabet/lookup-server/commit/f8246afe4c7c0b19bb17cede60ff45bcffc9ade1))
* **python:black:** test before generating a new release ([ce2fb0e](https://gitlab.mim-libre.fr/alphabet/lookup-server/commit/ce2fb0e950314cf50ebc5bd6d6b407628aaa222b))
* **semantic-release:** create `testing` prerelease ([2e98fab](https://gitlab.mim-libre.fr/alphabet/lookup-server/commit/2e98fab5a3191fb71edef1993746b4048fed28a0))
* **tag docker:** tag build created by release and prerelease ([b1701c5](https://gitlab.mim-libre.fr/alphabet/lookup-server/commit/b1701c56785518f2ae83b02c287f3473b827da3e))
# 1.0.0 (2022-01-13)
......
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from flask import Flask
from flask import Flask, request, abort
from flask_pymongo import PyMongo
from os import environ
from functools import wraps
__version__ = "1.0.0"
__version__ = "1.1.0"
print("Lookup-Server", __version__)
app = Flask(__name__)
print("MONGO_URI = ", environ["MONGO_URI"])
app.config["MONGO_URI"] = environ["MONGO_URI"]
print("LOOKUP_SERVER_API_KEY = ", environ["LOOKUP_SERVER_API_KEY"])
app.config["LOOKUP_SERVER_API_KEY"] = environ["LOOKUP_SERVER_API_KEY"]
try:
app.config["MONGO_LIMIT"] = int(environ["MONGO_LIMIT"])
except:
......@@ -17,3 +24,19 @@ except:
print("MONGO_LIMIT = ", app.config["MONGO_LIMIT"])
mongo = PyMongo(app)
# The actual decorator function
def require_appkey(view_function):
@wraps(view_function)
# the new, post-decoration function. Note *args and **kwargs here.
def decorated_function(*args, **kwargs):
if (
request.headers.get("x-api-key")
and request.headers.get("x-api-key") == app.config["LOOKUP_SERVER_API_KEY"]
):
return view_function(*args, **kwargs)
else:
abort(401)
return decorated_function
// No release is triggered for the types commented out below.
// Commits using these types will be incorporated into the next release.
//
// NOTE: Any changes here must be reflected in `CONTRIBUTING.md`.
module.exports = [
{breaking: true, release: 'major'},
// {type: 'build', release: 'patch'},
// {type: 'chore', release: 'patch'},
// {type: 'ci', release: 'patch'},
{type: 'docs', release: 'patch'},
{type: 'feat', release: 'minor'},
{type: 'fix', release: 'patch'},
{type: 'perf', release: 'patch'},
{type: 'refactor', release: 'patch'},
{type: 'revert', release: 'patch'},
{type: 'style', release: 'patch'},
{type: 'test', release: 'patch'},
];
// Build the configuration depending of the environnement
// When using prerelease branches, we don't want changelog to be generated
// See https://github.com/semantic-release/changelog/issues/51#issuecomment-682609394
// Gitlab reference name
const branch = process.env.CI_COMMIT_REF_NAME
const git_assets = []
const config = {
// It must match the name of your repository
branches: 'master',
tagFormat: 'release/${version}',
plugins: [
['@semantic-release/commit-analyzer', {
preset: 'angular',
releaseRules: './release-rules.js',
}],
'@semantic-release/release-notes-generator',
],
}
// Make sure the changelog is generated for release branch
// exclude any prerelease branches
if (!Array.isArray(config.branches)
|| config.branches.some(it => it === branch || (it.name === branch && !it.prerelease))) {
config.plugins.push(
['@semantic-release/changelog', {
changelogFile: 'docs/CHANGELOG.md',
changelogTitle: '# Changelog',
}])
git_assets.push('docs/CHANGELOG.md')
}
config.plugins.push(
['@semantic-release/git', {
assets: git_assets,
message: 'chore(release): ${nextRelease.version}\n\n${nextRelease.notes}'
}],
'@semantic-release/gitlab',
)
config.generateNotes = {
preset: 'angular',
writerOpts: {
// Required due to upstream bug preventing all types being displayed.
// Bug: https://github.com/conventional-changelog/conventional-changelog/issues/317
// Fix: https://github.com/conventional-changelog/conventional-changelog/pull/410
transform: (commit, context) => {
const issues = []
commit.notes.forEach(note => {
note.title = `BREAKING CHANGES`
})
// NOTE: Any changes here must be reflected in `CONTRIBUTING.md`.
if (commit.type === `feat`) {
commit.type = `Features`
} else if (commit.type === `fix`) {
commit.type = `Bug Fixes`
} else if (commit.type === `perf`) {
commit.type = `Performance Improvements`
} else if (commit.type === `revert`) {
commit.type = `Reverts`
} else if (commit.type === `docs`) {
commit.type = `Documentation`
} else if (commit.type === `style`) {
commit.type = `Styles`
} else if (commit.type === `refactor`) {
commit.type = `Code Refactoring`
} else if (commit.type === `test`) {
commit.type = `Tests`
} else if (commit.type === `build`) {
commit.type = `Build System`
// } else if (commit.type === `chore`) {
// commit.type = `Maintenance`
} else if (commit.type === `ci`) {
commit.type = `Continuous Integration`
} else {
return
}
if (commit.scope === `*`) {
commit.scope = ``
}
if (typeof commit.hash === `string`) {
commit.shortHash = commit.hash.substring(0, 7)
}
if (typeof commit.subject === `string`) {
let url = context.repository
? `${context.host}/${context.owner}/${context.repository}`
: context.repoUrl
if (url) {
url = `${url}/issues/`
// Issue URLs.
commit.subject = commit.subject.replace(/#([0-9]+)/g, (_, issue) => {
issues.push(issue)
return `[#${issue}](${url}${issue})`
})
}
if (context.host) {
// User URLs.
commit.subject = commit.subject.replace(/\B@([a-z0-9](?:-?[a-z0-9/]){0,38})/g, (_, username) => {
if (username.includes('/')) {
return `@${username}`
}
return `[@${username}](${context.host}/${username})`
})
}
}
// remove references that already appear in the subject
commit.references = commit.references.filter(reference => {
if (issues.indexOf(reference.issue) === -1) {
return true
}
return false
})
return commit
},
},
}
module.exports = config