Skip to content
Snippets Groups Projects
Unverified Commit 744f13f6 authored by Mael Gaonach's avatar Mael Gaonach
Browse files

build docker on tag

parent 229ed4ec
No related branches found
No related tags found
1 merge request!122Resolve "Dockerize"
workflow:
rules:
# Explicitly enable merge request pipelines to be created (not done by default)
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
# Run on all tags
- if: $CI_COMMIT_TAG
# Prevent duplicate pipelines from push events to branches that are the source
# branch of one or more open merge requests. If $CI_OPEN_MERGE_REQUESTS is
# non-empty on a branch pipeline, it means that the the above rule has already
# caused (or will cause) a merge request pipeline to run. These rules are
# separately evaluated for the merge request event resulting from the same push.
- if: $CI_COMMIT_BRANCH && $CI_OPEN_MERGE_REQUESTS
when: never
# Run a normal branch pipeline on a branch that isn't the source of an open MR
- if: $CI_COMMIT_BRANCH
stages: stages:
- validate - validate
- build
.pnpm: .setup_pnpm:
image: node:16-alpine
cache: &cache cache: &cache
key: '$CI_COMMIT_REF_SLUG' key: '$CI_COMMIT_REF_SLUG'
paths: paths:
- .pnpm-store - .pnpm-store
- ~/.cache
policy: pull-push policy: pull-push
before_script: before_script:
- npm install -g pnpm@8.2.0 - npm install -g pnpm@9.9.0
- pnpm config set store-dir .pnpm-store - pnpm config set store-dir .pnpm-store
- pnpm install - pnpm install
needs: []
.pnpm:
extends: .setup_pnpm
image: node:20-alpine
.only_tags: &only_tags
- if: $CI_COMMIT_TAG
when: always
- when: never
.only_tags_manual: &only_tags_manual
- if: $CI_COMMIT_TAG
when: manual
- when: never
.exclude_tags: &exclude_tags
- if: $CI_COMMIT_TAG
when: never
- when: always
.only_main_manual: &only_main_manual
- if: $CI_COMMIT_REF_NAME != $CI_DEFAULT_BRANCH
when: never
- when: manual
.only_main: &only_main
- if: $CI_COMMIT_REF_NAME != $CI_DEFAULT_BRANCH
when: never
- when: always
include: include:
- local: '.gitlab/*.yml' - local: '.gitlab/*.yml'
variables:
DOCKER_REGISTRY: $CI_REGISTRY/$CI_REGISTRY_IMAGE
.docker-template:
image: docker:latest
tags:
- docker
before_script:
- docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
build-and-publish:
extends: .docker-template
stage: build
tags:
- docker
script:
- docker build --pull -t "${DOCKER_REGISTRY}-doi-landing-page:${CI_COMMIT_REF_SLUG}" .
- docker push "${DOCKER_REGISTRY}-doi-landing-page:${CI_COMMIT_REF_SLUG}"
rules:
- !reference [.only_tags]
.setup_git: &setup_git
- apt-get update
- apt-get install -y git
- git tag -d $(git tag -l)
- git config --global user.email "gitlab@localhost"
- git config --global user.name "GitLab CI"
- git remote rm origin
# use token in $CI_TAG_TOKEN to have permission to push tag
- git remote add origin https://gitlab-ci-token:${CI_TAG_TOKEN}@${CI_REPOSITORY_URL#*@}
- git fetch --all
- git checkout $CI_COMMIT_REF_NAME
.release:
stage: release
needs: []
image: ubuntu:20.04
.create_tag:
extends: .release
rules:
- !reference [.only_main_manual]
before_script:
- *setup_git
- git branch --set-upstream-to=origin/$CI_COMMIT_REF_NAME $CI_COMMIT_REF_NAME
- git pull
release_patch:
extends: .create_tag
script:
- . scripts/create-tag.sh patch
release_minor:
extends: .create_tag
script:
- . scripts/create-tag.sh minor
release_major:
extends: .create_tag
script:
- . scripts/create-tag.sh major
...@@ -6,3 +6,5 @@ lint: ...@@ -6,3 +6,5 @@ lint:
parallel: parallel:
matrix: matrix:
- LINTER: [eslint, prettier, tsc] - LINTER: [eslint, prettier, tsc]
rules:
- !reference [.exclude_tags]
# build environment
FROM node:20-alpine AS build
WORKDIR /app
RUN npm install -g pnpm@9.9.0
# install dependencies
COPY . .
RUN pnpm install
# build app
RUN pnpm --filter doi-landing-page build
# production environment
FROM nginx:stable-alpine
COPY --from=build /app/apps/doi-landing-page/dist /usr/share/nginx/html/
COPY ./nginx.conf /etc/nginx/conf.d/default.conf
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
\ No newline at end of file
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
"type": "module", "type": "module",
"scripts": { "scripts": {
"dev": "vite", "dev": "vite",
"build": "tsc && vite build", "build": "vite build --mode prod",
"lint:eslint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0", "lint:eslint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"lint:tsc": "tsc", "lint:tsc": "tsc",
"lint:prettier": "prettier . --check", "lint:prettier": "prettier . --check",
......
server {
listen 0.0.0.0:80;
gzip on;
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_buffers 16 8k;
gzip_http_version 1.1;
gzip_min_length 1000;
gzip_types text/plain application/javascript text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/vnd.ms-fontobject application/x-font-ttf font/opentype;
root /usr/share/nginx/html;
index index.html index.htm;
location / {
try_files $uri $uri/ /index.html;
add_header 'Access-Control-Allow-Origin' '*';
expires -1;
}
location ~* \.(?:css|js)$ {
add_header 'Access-Control-Allow-Origin' '*';
add_header Cache-Control "no-cache, public, must-revalidate, proxy-revalidate";
}
location ~* \.(?:jpg|jpeg|gif|png|ico|xml|webp)$ {
add_header 'Access-Control-Allow-Origin' '*';
expires 5m;
add_header Cache-Control "public";
}
}
\ No newline at end of file
This diff is collapsed.
#!/bin/sh
# This script creates a tag for the current commit, by incrementing the current tag value, and pushes it to the remote repository
# first arg decribes the type of release (major, minor, patch)
release_type=$1
echo "Release type: $release_type"
git tag -d $(git tag -l) # delete all local tags
git pull # fetch all remote tags
current_tag=$(git describe --tags `git rev-list --tags --max-count=1`)
echo "Current tag: $current_tag"
major=$(echo $current_tag | cut -d. -f1)
minor=$(echo $current_tag | cut -d. -f2)
patch=$(echo $current_tag | cut -d. -f3)
if [ "$release_type" == "major" ]; then
major=$((major+1))
minor=0
patch=0
elif [ "$release_type" == "minor" ]; then
minor=$((minor+1))
patch=0
elif [ "$release_type" == "patch" ]; then
patch=$((patch+1))
else
echo "Invalid release type. Must be one of: major, minor, patch"
return 1
fi
new_tag="$major.$minor.$patch"
echo "Creating tag: $new_tag"
changelog=$(git log --pretty=oneline HEAD...$current_tag --decorate=False | grep "Merge branch" | grep -v 'https' | awk '{print $4}' | sed 's/-/ /g'| rev | cut -c2- | rev | sed "s/'/- #/g")
echo "Changelog:
$changelog
"
git tag -a $new_tag -m "$changelog"
git push origin $new_tag
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment