Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
DojoExerciseChecker
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
External wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Dojo Project (HES-SO)
Projects
Pipelines
DojoExerciseChecker
Commits
341fe00c
Commit
341fe00c
authored
1 year ago
by
michael.minelli
Browse files
Options
Downloads
Plain Diff
Merge branch 'release_by_ci-cd' into v2.0.0
parents
b72e369b
08da0d2f
No related branches found
No related tags found
No related merge requests found
Pipeline
#26325
passed
1 year ago
Stage: build
Stage: clean-same-release
Stage: release
Changes
2
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
.gitlab-ci.yml
+159
-28
159 additions, 28 deletions
.gitlab-ci.yml
CHANGELOG.md
+35
-0
35 additions, 0 deletions
CHANGELOG.md
with
194 additions
and
28 deletions
.gitlab-ci.yml
+
159
−
28
View file @
341fe00c
variables
:
variables
:
GIT_SUBMODULE_STRATEGY
:
recursive
GIT_SUBMODULE_STRATEGY
:
recursive
GIT_SUBMODULE_FORCE_HTTPS
:
"
true"
GIT_SUBMODULE_FORCE_HTTPS
:
"
true"
DOCKER_HOST
:
tcp://docker:2375
DOCKER_HOST
:
tcp://docker:2375
DOCKER_TLS_CERTDIR
:
DOCKER_TLS_CERTDIR
:
DOCKER_DRIVER
:
overlay2
DOCKER_DRIVER
:
overlay2
PROJECT_NAME
:
DojoExerciseChecker
VERSION_DEV_SUFFIX
:
'
-dev'
GITLAB_API_PROJECT_URL
:
${CI_API_V4_URL}/projects/${CI_PROJECT_ID}
DOCKERFILE
:
Dockerfile_ExerciseChecker
DOCKERFILE
:
Dockerfile_ExerciseChecker
PLATFORMS
:
linux/amd64,linux/arm64/v8
DOCKER_PLATFORMS
:
linux/amd64,linux/arm64/v8
CHECKER_PROJECT_FOLDER
:
ExerciseChecker
stages
:
PROJECT_FOLDER
:
ExerciseChecker
-
build
-
release
default
:
tags
:
.get_version
:
-
docker
script
:
image
:
docker:latest
-
IS_DEV=$([[ $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH ]] && echo
false
|| echo
true
)
services
:
-
VERSION=$(jq -r .version $PROJECT_FOLDER/package.json)$([[ $IS_DEV ==
true
]] && echo $VERSION_DEV_SUFFIX || echo '')
-
docker:dind
-
DOCKER_LOCAL_IMAGE_PATH=$ARTIFACTS_FOLDER/$VERSION.tar
before_script
:
.get_packages_url
:
script
:
-
PACKAGE_URL_DOCKER_IMAGE="${PACKAGE_REGISTRY_URL}/${VERSION}/${PROJECT_NAME}.tar"
.init_dind_script
:
script
:
# Install dependencies
-
apk update
-
apk update
-
apk add git
-
apk add git
-
apk add jq
-
apk add jq
-
docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
# Init docker buildx
-
docker login -u $DOCKER_REGISTRY_USER -p $DOCKER_REGISTRY_PASSWORD $DOCKER_REGISTRY
-
docker buildx create --use
-
docker buildx create --use
-
>
# Get version from package.json
VERSION=$(jq -r .version $CHECKER_PROJECT_FOLDER/package.json)
-
!reference
[
.get_version
,
script
]
-
>
-
CONTAINER_IMAGE=$DOCKER_REGISTRY_IMAGE:$VERSION
CONTAINER_IMAGE=$CI_REGISTRY_IMAGE:$VERSION-dev
build
:
.build_script
:
stage
:
build
tags
:
-
build
script
:
script
:
-
!reference
[
.init_dind_script
,
script
]
-
mkdir -p $ARTIFACTS_FOLDER
# Download secure files
-
apk add curl
-
apk add curl
-
curl --silent "https://gitlab.com/gitlab-org/incubation-engineering/mobile-devops/download-secure-files/-/raw/main/installer" | sh
-
curl --silent "https://gitlab.com/gitlab-org/incubation-engineering/mobile-devops/download-secure-files/-/raw/main/installer" | sh
-
mv .secure_files/env_$VERSION $
CHECKER_
PROJECT_FOLDER/.env
-
mv .secure_files/env_$VERSION $PROJECT_FOLDER/.env
# Need to build for each platform separately because of multi-stage builds (docker buildx don't use cache same way as docker build)
# Need to build for each platform separately because of multi-stage builds (docker buildx don't use cache same way as docker build)
-
>
-
>
platform_array=$(echo $PLATFORMS | tr "," "\n");
platform_array=$(echo $
DOCKER_
PLATFORMS | tr "," "\n");
for platform in $platform_array; do
for platform in $platform_array; do
echo "Buildind for : $platform"
echo "Buildind for : $platform"
docker buildx build --pull --platform $platform --file $DOCKERFILE --tag $CONTAINER_IMAGE .
docker buildx build --pull --platform $platform --file $DOCKERFILE --tag $CONTAINER_IMAGE .
done
done
.clean_release
:
script
:
# Delete release if it already exists
-
'
curl
--request
DELETE
--header
"JOB-TOKEN:
$CI_JOB_TOKEN"
"${GITLAB_API_PROJECT_URL}/releases/${VERSION}"'
# Delete tag if it already exists (use private-token because job-token don't have permission to delete tags)
-
'
curl
--request
DELETE
--header
"PRIVATE-TOKEN:
$GITLAB_PROJECT_ACCESS_TOKEN"
"${GITLAB_API_PROJECT_URL}/repository/tags/${VERSION}"'
stages
:
-
build
-
clean-same-release
-
clean-dev-release
-
release
build:test
:
stage
:
build
tags
:
-
build
-
dind
image
:
docker:latest
services
:
-
docker:dind
script
:
-
!reference
[
.build_script
,
script
]
rules
:
-
if
:
'
$CI_COMMIT_TAG
=~
"/^$/"
&&
$CI_COMMIT_BRANCH
!=
$CI_DEFAULT_BRANCH
&&
$CI_COMMIT_BRANCH
!~
/^v[0-9]+(\.[0-9]+)*$/'
build:version
:
stage
:
build
tags
:
-
build
-
dind
image
:
docker:latest
services
:
-
docker:dind
script
:
-
!reference
[
.build_script
,
script
]
# Here docker buildx can use cached images created in previous step
# Here docker buildx can use cached images created in previous step
-
docker buildx build --platform $PLATFORMS --file $DOCKERFILE --push --tag $CONTAINER_IMAGE .
-
docker buildx build --platform $DOCKER_PLATFORMS --file $DOCKERFILE --push --tag $CONTAINER_IMAGE .
rules
:
-
if
:
'
$CI_COMMIT_BRANCH
==
$CI_DEFAULT_BRANCH
||
$CI_COMMIT_BRANCH
=~
/^v[0-9]+(\.[0-9]+)*$/'
clean:release
:
stage
:
clean-same-release
tags
:
-
gitlab_clean
image
:
registry.gitlab.com/gitlab-ci-utils/curl-jq:latest
script
:
-
!reference
[
.get_version
,
script
]
-
!reference
[
.clean_release
,
script
]
rules
:
rules
:
-
if
:
'
$CI_COMMIT_BRANCH
==
$CI_DEFAULT_BRANCH
||
$CI_COMMIT_BRANCH
=~
/^v[0-9]+(\.[0-9]+)*$/'
-
if
:
'
$CI_COMMIT_BRANCH
==
$CI_DEFAULT_BRANCH
||
$CI_COMMIT_BRANCH
=~
/^v[0-9]+(\.[0-9]+)*$/'
release-image
:
clean-dev:release
:
stage
:
clean-dev-release
tags
:
-
gitlab_clean
image
:
registry.gitlab.com/gitlab-ci-utils/curl-jq:latest
script
:
-
!reference
[
.get_version
,
script
]
-
VERSION="${VERSION}${VERSION_DEV_SUFFIX}"
-
!reference
[
.clean_release
,
script
]
rules
:
-
if
:
'
$CI_COMMIT_BRANCH
==
$CI_DEFAULT_BRANCH'
clean:dockerhub:dev
:
stage
:
clean-dev-release
tags
:
-
clean
-
dind
image
:
docker:latest
services
:
-
docker:dind
script
:
-
!reference
[
.init_dind_script
,
script
]
-
VERSION="${VERSION}${VERSION_DEV_SUFFIX}"
# Remove dev tag
## Login to dockerhub (get JWT token)
-
GET_TOKEN_DATA=$(jq --null-input --arg username "$DOCKER_REGISTRY_USER" --arg password "$DOCKER_REGISTRY_PASSWORD" '{"username":$username,"password":$password}')
-
>
TOKEN=`curl --data "${GET_TOKEN_DATA}" \
--header "Content-Type: application/json" \
--header "JOB-TOKEN: $CI_JOB_TOKEN" \
"https://hub.docker.com/v2/users/login/" | jq -r .token`
## Delete tag
-
'
curl
--header
"Authorization:
JWT
${TOKEN}"
--request
DELETE
"https://hub.docker.com/v2/repositories/${DOCKER_REGISTRY_IMAGE}/tags/${VERSION}/"'
rules
:
-
if
:
'
$CI_COMMIT_BRANCH
==
$CI_DEFAULT_BRANCH'
release:dockerhub:latest
:
stage
:
release
stage
:
release
tags
:
tags
:
-
release
-
release
-
dind
image
:
docker:latest
services
:
-
docker:dind
script
:
script
:
-
docker buildx imagetools create $CONTAINER_IMAGE --tag $CI_REGISTRY_IMAGE:$VERSION
-
!reference
[
.init_dind_script
,
script
]
-
docker buildx imagetools create $CONTAINER_IMAGE --tag $CI_REGISTRY_IMAGE:latest
# Push latest tag
-
docker buildx imagetools create $CONTAINER_IMAGE --tag $DOCKER_REGISTRY_IMAGE:latest
rules
:
rules
:
-
if
:
'
$CI_COMMIT_BRANCH
==
$CI_DEFAULT_BRANCH'
-
if
:
'
$CI_COMMIT_BRANCH
==
$CI_DEFAULT_BRANCH'
release_job
:
stage
:
release
tags
:
-
release
image
:
registry.gitlab.com/gitlab-ci-utils/curl-jq:latest
script
:
-
!reference
[
.get_version
,
script
]
-
!reference
[
.get_packages_url
,
script
]
-
echo 'Running release_job'
# Extract description from CHANGELOG.md
-
CHANGELOG_LINE_START=`awk '/##\ [0-9]+\.[0-9]+\.[0-9]+/{print NR; exit;}' CHANGELOG.md`
-
CHANGELOG_LINE_END=`awk '/##\ [0-9]+\.[0-9]+\.[0-9]+/{ count++; if(count>1) {print NR; exit;}}' CHANGELOG.md`
-
DESCRIPTION=`awk 'NR > '$CHANGELOG_LINE_START' && NR < '$CHANGELOG_LINE_END'' CHANGELOG.md`
# Create Release (can't be done by release_step of gitlab image because it don't have access to env var defined in script_step)
-
>
RELEASE_DATA=$(jq --null-input --arg version "$VERSION" --arg description "# Changelog (version $VERSION) $DESCRIPTION" --arg tag_name "$VERSION" --arg ref "$CI_COMMIT_SHORT_SHA" '{
"name": $version,
"description": $description,
"tag_name": $tag_name,
"ref": $ref
}')
-
>
curl --data "${RELEASE_DATA}" \
--header "Content-Type: application/json" \
--header "JOB-TOKEN: $CI_JOB_TOKEN" \
--request POST "${GITLAB_API_PROJECT_URL}/releases"
rules
:
-
if
:
'
$CI_COMMIT_BRANCH
==
$CI_DEFAULT_BRANCH
||
$CI_COMMIT_BRANCH
=~
/^v[0-9]+(\.[0-9]+)*$/'
\ No newline at end of file
This diff is collapsed.
Click to expand it.
CHANGELOG.md
0 → 100644
+
35
−
0
View file @
341fe00c
# Changelog
<!--
### ✨ Feature
### 🤏 Minor change
### 🎨 Interface
### 🐛 Bugfix
### 🔒 Security
### 🚀️ CI / CD
### 🔨 Internal / Developers
### 📚 Documentation
**💥 Breaking:**
**⚠️ Deprecation:**
-->
## 2.0.0 (2023-09-15)
### ✨ Feature
-
Added license: AGPLv3
### 🎨 Interface
-
**💥 Breaking:**
Renamed
`enonce`
to
`assignment`
-
**💥 Breaking:**
Renamed
`exercice`
to
`exercise`
### 🔨 Internal / Developers
-
Auto release by pipeline
-
For vX.Y.Z branch create release and tag with
`-dev`
suffix
-
For main branch create definitive release and remove
`-dev`
releases
## 1.0.1 (2023-08-12)
### ✨ Feature
-
🎉 Initial release of the project
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment