Commit fc9c830a authored by Jacek Lebioda's avatar Jacek Lebioda
Browse files

feat: some progress on new CI/CD pipeline

parent d6b68bc0
Pipeline #23319 failed with stages
in 21 seconds
#!/bin/bash #!/bin/bash
DIRECTORY=build
# Install lunr to build the index # Install lunr to build the index
npm install lunr@2.3.8 npm install lunr@$LUNR_VERSION
# Go to the directory... # Go to the directory containing the built website...
cd $DIRECTORY cd $DIRECTORY
printf "Found the following build targets inside: \n$(ls -d */)\n\n" echo "Generating the index..."
# ...and loop through all the build targets
for branch in $(ls -d */); do
echo "Entering: $branch";
cd "$branch";
echo "Generating the index..."
cat documents.js | node $CI_PROJECT_DIR/build_index.js > index.js
rm documents.js build_index.js
echo "...should be completed. First 50 characters of the index: " # Pipe documents.js file (which should be generated by Jekyll after building the website) through build script
cat index.js | head -c50 cat documents.js | node build_index.js > index.js
echo ""
cd .. # Show the results (should not be empty)
echo "...should be completed. First 50 characters of the index: "
done cat index.js | head -c50
echo ""
rm $CI_PROJECT_DIR/build_index.js rm documents.js build_index.js
mkdir -p build
artefact="latest"
# loop through all the branches
for branch in $(git for-each-ref --format='%(refname:strip=3)' refs/remotes); do
echo $branch;
if [[ $branch == "master" ]]; then
artefact="stable";
elif [[ $branch == "develop" ]]; then
artefact="latest";
else
artefact="unstable";
fi
echo $artefact;
git checkout -f $branch
git reset --hard $branch
git pull
# build the website
bundle install
bundle exec jekyll build --baseurl="howto-cards/$artefact" -d "build/$artefact"
if [[ $branch == "master" ]]; then
# set the 404
cp howto-cards/$artefact/404.html build/404.html
fi
done
# checkout the current branch
echo $CI_COMMIT_REF_NAME
git checkout -f $CI_COMMIT_REF_NAME
git reset --hard origin/$CI_COMMIT_REF_NAME
# set the auto redirection
cp .ci/.autoRedirect build/index.html
...@@ -8,27 +8,35 @@ stages: ...@@ -8,27 +8,35 @@ stages:
build_pages: build_pages:
stage: build stage: build
before_script:
- apt-get -qq update
- apt-get install -y -qq git-lfs
- gem install bundler:2.0.2 && bundle install
script:
- bash .ci/deploy.sh
variables: variables:
JEKYLL_ENV: production JEKYLL_ENV: production
BUNDLER_VERSION: 2.0.2
artifacts: artifacts:
expire_in: 1 day expire_in: 1 day
paths: paths:
- build - build
before_script:
- gem install bundler:$BUNDLER_VERSION && bundle install
script:
# Generate the configuration for forks (will use Gitlab Pages on personal namespaces)
- 'echo "url: https://$CI_PROJECT_NAMESPACE.$CI_PAGES_DOMAIN\nbaseurl: /$CI_PROJECT_NAME" >> _config_gitlab_pages.yml'
# If there is no config for the current branch, use the one for Gitlab Pages
- 'if [ ! -f "_config_$CI_COMMIT_REF_NAME.yml" ]; then mv _config_gitlab_pages.yml _config_$CI_COMMIT_REF_NAME.yml; fi'
# Display, which configuration is used
- 'echo "Configuration: " && cat "_config_$CI_COMMIT_REF_NAME.yml"'
# Run Jekyll with custom configuration
- bundle exec jekyll build -d build --config "_config.yml,_config_$CI_COMMIT_REF_NAME.yml"
generate the search index: generate the search index:
stage: generate_index stage: generate_index
image: node:13.8.0-slim image: node:13.8.0-slim
rules: variables:
- if: $CI_COMMIT_BRANCH == "master" LUNR_VERSION: 2.3.8
- if: $CI_COMMIT_BRANCH == "develop" DIRECTORY: build
- if: $CI_COMMIT_BRANCH == "16-deploy-to-staticpages-vm"
script: script:
- bash .ci/build_indices.sh - bash .ci/build_indices.sh
- mv build processed_build - mv build processed_build
...@@ -37,14 +45,16 @@ generate the search index: ...@@ -37,14 +45,16 @@ generate the search index:
paths: paths:
- processed_build - processed_build
# Deploy to Gitlab Pages - to be run only by forks
pages: pages:
image: alpine:3.11.3 image: alpine:3.11.3
stage: deploy stage: deploy
rules: rules:
- if: $CI_COMMIT_BRANCH == "master" - if: '$CI_PROJECT_NAMESPACE != "R3" && $CI_PROJECT_NAMESPACE != "R3-core"'
- if: $CI_COMMIT_BRANCH == "develop"
script: script:
- mv processed_build public # For safety reasons:
- sleep 3600 && exit -1
- mv processed_buildXXXXX publicXXXX
artifacts: artifacts:
expire_in: 1 week expire_in: 1 week
paths: paths:
...@@ -67,7 +77,9 @@ Deploy to production: ...@@ -67,7 +77,9 @@ Deploy to production:
- if: '$CI_COMMIT_BRANCH == "master" && $CI_PROJECT_PATH == "R3/howto-cards"' - if: '$CI_COMMIT_BRANCH == "master" && $CI_PROJECT_PATH == "R3/howto-cards"'
- if: '$CI_COMMIT_BRANCH == "16-deploy-to-staticpages-vm"' - if: '$CI_COMMIT_BRANCH == "16-deploy-to-staticpages-vm"'
script: script:
- ssh -p $SSHPORT $SSHCONNECT "mkdir -p ~/sources/public/web_$CI_JOB_ID ~/master" # Disable that for now
- sleep 3600 && exit -1
- ssh -p $SSHPORT $SSHCONNECT "mkdir -p ~/sources/$CI_COMMIT_BRANCH/$CI_JOB_ID ~/master ~/develop"
- scp -P $SSHPORT -r processed_build/* $SSHCONNECT:~/sources/public/web_$CI_JOB_ID - scp -P $SSHPORT -r processed_build/* $SSHCONNECT:~/sources/public/web_$CI_JOB_ID
- ssh -p $SSHPORT $SSHCONNECT "cd ~/master && ln -fs ~/sources/public/web_$CI_JOB_ID/* . && cd ~/sources/public/ && find . -type d -not -newermt '-1 minutes' -exec rm -rf {} +;" - ssh -p $SSHPORT $SSHCONNECT "cd ~/master && ln -fs ~/sources/public/web_$CI_JOB_ID/* . && cd ~/sources/public/ && find . -type d -not -newermt '-1 minutes' -exec rm -rf {} +;"
...@@ -19,8 +19,8 @@ description: >- # this means to ignore newlines until "baseurl:" ...@@ -19,8 +19,8 @@ description: >- # this means to ignore newlines until "baseurl:"
This page is an index for lab cards that are intended to provide practical guidance in implementing Data Management, Data Protection and IT setup. This page is an index for lab cards that are intended to provide practical guidance in implementing Data Management, Data Protection and IT setup.
# URL settings (the most difficult part, please refer to the guide) # URL settings (the most difficult part, please refer to the guide)
baseurl: "/howto-cards" # the subpath of your site, e.g. /gitlab-repository-name baseurl: "/" # the subpath of your site, e.g. /gitlab-repository-name
url: "https://r3.pages.uni.lu" # the base hostname & protocol for your site, e.g. http://gitlab-namespace-name.pages.uni.lu/ url: "https://localhost" # the base hostname & protocol for your site, e.g. http://gitlab-namespace-name.pages.uni.lu/
# Banner settings # Banner settings
banner: howto-card # When you have custom images, change this setting's value to the name of the folder containing them banner: howto-card # When you have custom images, change this setting's value to the name of the folder containing them
...@@ -62,6 +62,8 @@ plugins: ...@@ -62,6 +62,8 @@ plugins:
# The display logic itself is in the template # The display logic itself is in the template
share_url: https://howto.lcsb.uni.lu/? share_url: https://howto.lcsb.uni.lu/?
include_link_index: 4 include_link_index: 4
# These values are injected into cards
defaults: defaults:
- -
scope: scope:
......
url: "https://howto-latest.lcsb.uni.lu"
baseurl: "/"
url: "https://howto.lcsb.uni.lu"
baseurl: "/"
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment