Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
V
ViaResto-website
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container 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
Aymeric Chaumont
ViaResto-website
Commits
9d168517
Commit
9d168517
authored
3 years ago
by
Antoine Gaudron-Desjardins
Browse files
Options
Downloads
Patches
Plain Diff
ci
parent
11e92319
No related branches found
No related tags found
1 merge request
!6
Ci
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
backend/.gitlab-ci.yml
+188
-0
188 additions, 0 deletions
backend/.gitlab-ci.yml
backend/docker-compose.yml
+1
-1
1 addition, 1 deletion
backend/docker-compose.yml
with
189 additions
and
1 deletion
backend/.gitlab-ci.yml
0 → 100644
+
188
−
0
View file @
9d168517
image
:
python:3.9
variables
:
MYSQL_DATABASE
:
$MYSQL_DATABASE
MYSQL_ROOT_PASSWORD
:
$MYSQL_ROOT_PASSWORD
MYSQL_USER
:
$MYSQL_USER
MYSQL_PASSWORD
:
$MYSQL_PASSWORD
MYSQL_DATABASE
:
$MYSQL_DATABASE
services
:
-
name
:
mysql:latest
command
:
[
"
mysqld"
,
"
--authentication-policy=mysql_native_password"
]
alias
:
mysql
# services:
# - name: mysql:latest
# command: ["mysqld", "--authentication-policy=mysql_native_password"]
# alias: mysql
# variables:
# MYSQL_DATABASE: $MYSQL_DATABASE
# MYSQL_ROOT_PASSWORD: $MYSQL_ROOT_PASSWORD
# Host: mysql
# User: $MYSQL_USER
# Password: $MYSQL_PASSWORD
# Database: $MYSQL_DATABASE
# cache:
# paths:
# - .cache/pip
# - venv/
# - env/
# before_script:
# - python --version # For debugging
# - pip install venv
# - python3 -m venv /venv
# - source /venv/bin/activate
stages
:
-
build
-
test
-
deploy
workflow
:
rules
:
-
if
:
'
$CI_PIPELINE_SOURCE
==
"merge_request_event"'
-
if
:
$CI_COMMIT_BRANCH
# include:
# - template: 'Code-Quality.gitlab-ci.yml'
#######################################################################################################################################
#### ####
#### Install dependencies ####
#### ####
#######################################################################################################################################
install
:
stage
:
build
script
:
-
pip install venv
-
python3 -m venv ./venv
-
source ./venv/bin/activate
-
pip install --upgrade pip && pip install pip-tools
-
pip install -r requirements.txt
artifacts
:
paths
:
-
.venv/
expire_in
:
30 mins
#######################################################################################################################################
#### ####
#### Testing code integration ####
#### ####
#######################################################################################################################################
lint
:
stage
:
test
allow_failure
:
false
before_script
:
-
source .venv/bin/activate
-
pip install pylint
script
:
-
pylint --recursive=y ./
format
:
stage
:
test
needs
:
lint
before_script
:
-
source .venv/bin/activate
-
pip install autopep8
script
:
-
autopep8 --in-place --recursive .
test
:
stage
:
test
variables
:
MYSQL_DATABASE
:
$MYSQL_DATABASE
MYSQL_ROOT_PASSWORD
:
$MYSQL_ROOT_PASSWORD
MYSQL_DATABASE
:
$MYSQL_DATABASE
MYSQL_USER
:
$MYSQL_USER
MYSQL_PASSWORD
:
$MYSQL_PASSWORD
DB_HOST
:
mysql
DB_PORT
:
3306
WEB_ROOT
:
http://localhost:3000
# SECRET_KEY: $SECRET_KEY
# TEST: "TRUE"
# STATIC_ROOT: "./"
# DJANGO_DEBUG: "FALSE"
# ALLOWED_HOSTS: ""
# DB_ENGINE: $ENGINE
# DB_NAME: $POSTGRES_DB
# DB_USER: $POSTGRES_USER
# DB_PASSWORD: $POSTGRES_PASSWORD
# DB_HOST: $POSTGRES_DB_HOST
# DB_PORT: 5432
before_script
:
-
source .venv/bin/activate
script
:
-
python -m uvicorn main:app --port=80 --host 0.0.0.0
-
curl "http://localhost/api/health"
#######################################################################################################################################
#### ####
#### Deploy ####
#### ####
#######################################################################################################################################
.deploy
:
stage
:
deploy
script
:
# Install ssh-agent if not already installed, it is required by Docker.
-
'
which
ssh-agent
||
(
apt-get
update
-y
&&
apt-get
install
openssh-client
-y
)'
# Run ssh-agent (inside the build environment)
-
eval $(ssh-agent -s)
# Add the SSH key stored in PRIVATE_KEY variable to the agent store
-
ssh-add <(echo "$PRIVATE_KEY")
# For Docker builds disable host key checking. Be aware that by adding that
# you are suspectible to man-in-the-middle attacks.
# WARNING: Use this only with the Docker executor, if you use it with shell
# you will overwrite your user's SSH config.
-
mkdir -p ~/.ssh
-
chmod 700 ~/.ssh
-
'
[[
-f
/.dockerenv
]]
&&
echo
-e
"Host
*\n\tStrictHostKeyChecking
no\n\n"
>
~/.ssh/config'
# In order to properly check the server's host key, assuming you created the
# SSH_SERVER_HOSTKEYS variable previously, uncomment the following two lines
# instead.
# - mkdir -p ~/.ssh
# - '[[ -f /.dockerenv ]] && echo "$SSH_SERVER_HOSTKEYS" > ~/.ssh/known_hosts'
# Get build job ID from file in artifact
# - job_id=$(cat job_id)
-
>
ssh "eatfast@$DOMAIN"
"cd /var/www/backend &&
git stash &&
git checkout "$CI_COMMIT_BRANCH" &&
git stash &&
git pull &&
docker-compose build &&
docker-compose up -d &&
exit"
# deploy-staging:
# extends: .deploy
# rules:
# - if: $CI_COMMIT_BRANCH == $STAGING_BRANCH
# when: always
# variables:
# DOMAIN: nofist.test.viarezo.fr
# PRIVATE_KEY: "$SSH_PRIVATE_KEY_STAGING"
deploy-prod
:
extends
:
.deploy
rules
:
-
if
:
$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
when
:
always
variables
:
DOMAIN
:
morbiustvplus.cs-campus.fr
PRIVATE_KEY
:
"
$SSH_PRIVATE_KEY"
This diff is collapsed.
Click to expand it.
backend/docker-compose.yml
+
1
−
1
View file @
9d168517
...
@@ -2,7 +2,7 @@ version: "3.3"
...
@@ -2,7 +2,7 @@ version: "3.3"
services
:
services
:
db
:
db
:
image
:
mysql
image
:
mysql
:latest
container_name
:
"
db"
container_name
:
"
db"
restart
:
always
restart
:
always
env_file
:
.env
env_file
:
.env
...
...
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