Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
Lab-GitLab-CI-CD
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Package registry
Model registry
Operate
Environments
Terraform modules
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
repos.quentin.fasler
Déploiement et Cloud
Lab-GitLab-CI-CD
Commits
7e28a935
Commit
7e28a935
authored
1 year ago
by
quentin.fasler
Browse files
Options
Downloads
Patches
Plain Diff
test
parent
46a4262e
No related branches found
No related tags found
No related merge requests found
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
.gitlab-ci copy.yml
+39
-0
39 additions, 0 deletions
.gitlab-ci copy.yml
.gitlab-ci.yml
+16
-23
16 additions, 23 deletions
.gitlab-ci.yml
with
55 additions
and
23 deletions
.gitlab-ci copy.yml
0 → 100644
+
39
−
0
View file @
7e28a935
variables
:
APP_PAGE
:
"
public/index.html"
CLONE_URL_SSH
:
"
ssh://git@ssh.hesge.ch:${CI_PROJECT_ID}"
CLONE_URL_TOK
:
"
https://gitlab-ci-token:${CI_JOB_TOKEN}@gitedu.hesge.ch"
stages
:
-
test
-
deploy
# Uncomment this when youf're ready to use the deploy stage
default
:
before_script
:
-
apk -U add git openssh-client rsync
-
mkdir -p -m 0700 ~/.ssh
-
touch ~/.ssh/known_hosts && chmod 644 ~/.ssh/known_hosts
-
'
[[
-f
/.dockerenv
]]
&&
echo
-e
"Host
*\n\tStrictHostKeyChecking
no\n\n"
>>
~/.ssh/config'
-
git config --global user.email "deployer@ci-cd.lab"
-
git config --global user.name "The Deployer"
-
eval $(ssh-agent -s)
-
echo "$SSH_PRIVATE_KEY" | ssh-add -
# Replace with environment variable for SSH key
-
echo "$SSH_KNOWN_HOSTS" >> ~/.ssh/known_hosts
unit_test1
:
stage
:
test
script
:
-
echo "This job tests the version string format in '${APP_PAGE}'"
-
git clone --depth=1 ${CLONE_URL_TOK}/${CI_PROJECT_PATH}
-
'
[[
$(sed
-nr
"/^\s*Version:\s+([[:digit:]]\.){2}[[:digit:]]\s*\$/p"
${CI_PROJECT_NAME}/${APP_PAGE}
|
wc
-l)
-eq
1
]]
||
{
echo
"[error]
Version
string
badly
formatted
or
not
found";
exit
1;
}'
deploy_prod
:
stage
:
deploy
environment
:
name
:
production
url
:
http://${PRODUCTION_IP}
script
:
-
echo "Deploying from ${CI_REPOSITORY_URL}::${CI_COMMIT_REF_NAME}"
-
rsync --rsync-path="sudo rsync" -Cavh ${CI_PROJECT_DIR}/public/ ${SSH_USER}@${PRODUCTION_IP}:${WEB_ROOT}
only
:
-
main
This diff is collapsed.
Click to expand it.
.gitlab-ci.yml
+
16
−
23
View file @
7e28a935
variables
:
---
APP_PAGE
:
"
public/index.html"
CLONE_URL_SSH
:
"
ssh://git@ssh.hesge.ch:${CI_PROJECT_ID}"
CLONE_URL_TOK
:
"
https://gitlab-ci-token:${CI_JOB_TOKEN}@gitedu.hesge.ch"
stages
:
stages
:
-
test
#
- test
-
deploy
# Uncomment this when youf're ready to use the deploy stage
-
deploy
default
:
default
:
before_script
:
before_script
:
-
apk -U add git openssh-client rsync
-
apk update
-
mkdir -p -m 0700 ~/.ssh
-
apk add openssh-client rsync
-
touch ~/.ssh/known_hosts && chmod 644 ~/.ssh/known_hosts
-
'
[[
-f
/.dockerenv
]]
&&
echo
-e
"Host
*\n\tStrictHostKeyChecking
no\n\n"
>>
~/.ssh/config'
-
git config --global user.email "deployer@ci-cd.lab"
-
git config --global user.name "The Deployer"
-
eval $(ssh-agent -s)
-
eval $(ssh-agent -s)
-
echo "$SSH_PRIVATE_KEY" | ssh-add -
# Replace with environment variable for SSH key
-
echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add -
-
mkdir ~/.ssh
# ssh-keyscan -t ecdsa-sha2-nistp256 86.119.42.85
-
echo "$SSH_KNOWN_HOSTS" >> ~/.ssh/known_hosts
-
echo "$SSH_KNOWN_HOSTS" >> ~/.ssh/known_hosts
unit_test1
:
# unit_test1:
stage
:
test
# stage: test
script
:
# script:
-
echo "This job tests the version string format in '${APP_PAGE}'"
# - git clone $CI_REPOSITORY_URL # Clone our repo locally
-
git clone --depth=1 ${CLONE_URL_TOK}/${CI_PROJECT_PATH}
# - app_version=$(<app_version_file) # Read the app version number from a file
-
'
[[
$(sed
-nr
"/^\s*Version:\s+([[:digit:]]\.){2}[[:digit:]]\s*\$/p"
${CI_PROJECT_NAME}/${APP_PAGE}
|
wc
-l)
-eq
1
]]
# - if [ "$app_version" != "expected_version" ]; then exit 1; fi # Check the app version and exit if wrong
||
{
echo
"[error]
Version
string
badly
formatted
or
not
found";
exit
1;
}'
deploy_prod
:
deploy_prod
:
stage
:
deploy
stage
:
deploy
...
@@ -34,6 +27,6 @@ deploy_prod:
...
@@ -34,6 +27,6 @@ deploy_prod:
url
:
http://${PRODUCTION_IP}
url
:
http://${PRODUCTION_IP}
script
:
script
:
-
echo "Deploying from ${CI_REPOSITORY_URL}::${CI_COMMIT_REF_NAME}"
-
echo "Deploying from ${CI_REPOSITORY_URL}::${CI_COMMIT_REF_NAME}"
-
rsync -
-rsync-path="sudo rsync" -Cavh ${CI_PROJECT_DIR}/public/ ${SSH_USER}@${PRODUCTION_IP}:${WEB_ROOT}
-
rsync -
rav --delete-after --progress ./public/* terraform@"$PRODUCTION_IP":/usr/share/nginx/html
only
:
only
:
-
main
-
main
\ 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