Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
R3
howto-cards
Commits
62c2ae21
Commit
62c2ae21
authored
Mar 27, 2020
by
Jacek Lebioda
Browse files
feat: double deployment
parent
0207c873
Pipeline
#23471
passed with stages
in 1 minute and 16 seconds
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
.ci/build_indices.sh
View file @
62c2ae21
#!/bin/bash
DIRECTORY
=
build
# Install lunr to build the index
npm
install
lunr@
$LUNR_VERSION
npm
install
lunr@
2.3.8
# Go to the directory
containing the built website
...
# Go to the directory...
cd
$DIRECTORY
echo
"Generating the index..."
printf
"Found the following build targets inside:
\n
$(
ls
-d
*
/
)
\n\n
"
# ...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
# Pipe documents.js file (which should be generated by Jekyll after building the website) through build script
cat
documents.js | node build_index.js
>
index.js
echo
"...should be completed. First 50 characters of the index: "
cat
index.js |
head
-c50
echo
""
# Show the results (should not be empty)
echo
"...should be completed. First 50 characters of the index: "
cat
index.js |
head
-c50
echo
""
cd
..
done
rm
documents.js
build_index.js
rm
$CI_PROJECT_DIR
/
build_index.js
.ci/build_indices_new.sh
0 → 100644
View file @
62c2ae21
#!/bin/bash
# Install lunr to build the index
npm
install
lunr@
$LUNR_VERSION
# Go to the directory containing the built website...
cd
$DIRECTORY
echo
"Generating the index..."
# Pipe documents.js file (which should be generated by Jekyll after building the website) through build script
cat
documents.js | node build_index.js
>
index.js
# Show the results (should not be empty)
echo
"...should be completed. First 50 characters of the index: "
cat
index.js |
head
-c50
echo
""
rm
documents.js build_index.js
.ci/deploy.sh
0 → 100644
View file @
62c2ae21
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
--url
=
"https://r3.pages.uni.lu"
--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
.gitlab-ci.yml
View file @
62c2ae21
...
...
@@ -6,15 +6,71 @@ stages:
-
generate_index
-
deploy
# !!!!!!! README !!!!!
# We are in the transition period - and the website is deployed two times - to gitlab pages and to a separate VM
# In order to migrate to a new deployment:
# 1) remove "Old deployment section" - build_pages, generate the search index and pages tasks
# 2) rename "new pages" to "pages" in the new deployment section, and "new_public" to "public"
# 3) remove ".ci/deploy.sh", ".ci/build_indices.sh"
# Old deployment =================================================================
build_pages
:
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
:
JEKYLL_ENV
:
production
BUNDLER_VERSION
:
2.0.2
artifacts
:
expire_in
:
1 day
paths
:
-
build
generate the search index
:
stage
:
generate_index
image
:
node:13.8.0-slim
rules
:
-
if
:
$CI_COMMIT_BRANCH == "master"
-
if
:
$CI_COMMIT_BRANCH == "develop"
script
:
-
bash .ci/build_indices.sh
-
mv build processed_build
artifacts
:
expire_in
:
1 day
paths
:
-
processed_build
pages
:
image
:
alpine:3.11.3
stage
:
deploy
rules
:
-
if
:
$CI_COMMIT_BRANCH == "master"
-
if
:
$CI_COMMIT_BRANCH == "develop"
script
:
-
mv processed_build public
artifacts
:
expire_in
:
1 week
paths
:
-
public
# New deployment ==================================================================
build pages for VM deployment
:
stage
:
build
variables
:
JEKYLL_ENV
:
production
BUNDLER_VERSION
:
2.0.2
artifacts
:
expire_in
:
1 day
paths
:
-
new_build
before_script
:
-
gem install bundler:$BUNDLER_VERSION && bundle install
script
:
...
...
@@ -29,40 +85,38 @@ build_pages:
-
'
echo
"Configuration:
"
&&
cat
".ci/_config_$CI_COMMIT_REF_NAME.yml"'
# Run Jekyll with custom configuration
-
bundle exec jekyll build -d build --config "_config.yml,.ci/_config_$CI_COMMIT_REF_NAME.yml"
-
bundle exec jekyll build -d
new_
build --config "_config.yml,.ci/_config_$CI_COMMIT_REF_NAME.yml"
generate the search index
:
generate the search index
for VM deployment
:
stage
:
generate_index
image
:
node:13.8.0-slim
variables
:
LUNR_VERSION
:
2.3.8
DIRECTORY
:
build
DIRECTORY
:
new_
build
script
:
-
bash .ci/build_indices.sh
-
mv build processed_build
-
bash .ci/build_indices
_new
.sh
-
mv build
new_
processed_build
artifacts
:
expire_in
:
1 day
paths
:
-
processed_build
-
new_
processed_build
# Deploy to Gitlab Pages - to be run only by forks
pages
:
# Deploy to Gitlab Pages - to be run only by forks
; change to pages once it's ready
new
pages
:
image
:
alpine:3.11.3
stage
:
deploy
rules
:
-
if
:
'
$CI_PROJECT_NAMESPACE
!=
"R3"
&&
$CI_PROJECT_NAMESPACE
!=
"R3-core"'
script
:
# For safety reasons:
-
sleep 3600 && exit -1
-
mv processed_buildXXXXX publicXXXX
-
mv new_processed_build new_public
artifacts
:
expire_in
:
1 week
paths
:
-
public
-
new_
public
## Deploys the website to a separate VM
D
eploy to production
:
d
eploy to production
:
stage
:
deploy
image
:
alpine:3.1
before_script
:
...
...
@@ -79,6 +133,6 @@ Deploy to production:
-
if
:
'
$CI_COMMIT_BRANCH
==
"16-deploy-to-staticpages-vm"'
script
:
-
ssh -p $SSHPORT $SSHCONNECT "mkdir -p ~/sources/public/$CI_COMMIT_BRANCH/$CI_JOB_ID ~/master/public ~/develop/public ~/$CI_COMMIT_BRANCH/public"
-
scp -P $SSHPORT -r processed_build/* $SSHCONNECT:~/sources/public/$CI_COMMIT_BRANCH/$CI_JOB_ID
-
scp -P $SSHPORT -r
new_
processed_build/* $SSHCONNECT:~/sources/public/$CI_COMMIT_BRANCH/$CI_JOB_ID
-
ssh -p $SSHPORT $SSHCONNECT "cd ~/$CI_COMMIT_BRANCH/public && ln -fs ~/sources/public/$CI_COMMIT_BRANCH/$CI_JOB_ID/* . && cd ~/sources/public/$CI_COMMIT_BRANCH && find . -type d -not -newermt '-1 minutes' -exec rm -rf {} +;"
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment