Merge branch 'update-ci' into 'develop'

Update CI/CD

See merge request ldc-web/projets/le-gaulois-pro!94
This commit is contained in:
Vincent BRIDIER 2023-03-15 15:09:53 +00:00
commit d090e68e28
6 changed files with 176 additions and 389 deletions

View file

@ -1,341 +1,24 @@
include:
- project: 'ldc-web/shared-ci'
ref: 'main'
file: 'lint/lint7.3.yml'
- project: 'ldc-web/shared-ci'
ref: 'main'
file: 'security/security7.3.yml'
- project: 'ldc-web/shared-ci'
ref: 'main'
file: 'build/build7.3.yml'
- project: 'ldc-web/shared-ci'
ref: 'main'
file: 'test/test.yml'
- project: 'ldc-web/shared-ci'
ref: 'main'
file: 'deploy/deploy.yml'
stages:
- Security
- CodingStandards
- DepBuildsTests
- DepBuilds
- Build
- Deploy
composer-security:
stage: Security
image: $CI_REGISTRY/service-web-lab/ldc-web-images-docker/ldcweb-qa:php7.3-1.0
script:
- local-php-security-checker --format=json --path=./composer.lock > composer-security-checker-report.json
artifacts:
when: on_failure
expose_as: 'composer-security-checker'
paths:
- composer-security-checker-report.json
allow_failure: true
needs: []
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
- if: $CI_COMMIT_BRANCH == "develop"
npm-security:
stage: Security
image: node:17.9.1
before_script:
- npm install --location=global audit-ci@^6
script:
- audit-ci -p npm -o json > npm-security-checker-report.json
artifacts:
when: on_failure
expose_as: 'npm-security-checker'
paths:
- npm-security-checker-report.json
allow_failure: true
needs: []
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
- if: $CI_COMMIT_BRANCH == "develop"
phpcs:
stage: CodingStandards
image: $CI_REGISTRY/service-web-lab/ldc-web-images-docker/ldcweb-qa:php7.3-1.0
before_script:
- composer config gitlab-token.gitlab.com $CI_DEPLOY_USER $CI_DEPLOY_PASSWORD
- composer install
script:
- vendor/bin/phpcs --report=junit --report-file=phpcs-report.xml
artifacts:
when: on_failure
expose_as: 'phpcs'
paths:
- phpcs-report.xml
reports:
junit: phpcs-report.xml
allow_failure: false
needs:
- composer-security
- npm-security
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
- if: $CI_COMMIT_BRANCH == "develop"
eslint:
stage: CodingStandards
image: node:17.9.0
before_script:
- npm install
cache:
paths:
- node_modules/
script:
- npm run eslint-ci --silent > eslint-report.xml
artifacts:
when: on_failure
expose_as: 'eslint'
paths:
- eslint-report.xml
reports:
junit: eslint-report.xml
allow_failure: false
needs:
- composer-security
- npm-security
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
- if: $CI_COMMIT_BRANCH == "develop"
stylelint:
stage: CodingStandards
image: node:17.9.0
before_script:
- npm install
cache:
paths:
- node_modules/
script:
- npm run stylelint-ci --silent > stylelint-report.json
artifacts:
when: on_failure
expose_as: 'stylelint'
paths:
- stylelint-report.json
allow_failure: false
needs:
- composer-security
- npm-security
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
- if: $CI_COMMIT_BRANCH == "develop"
front-build-test:
stage: DepBuildsTests
image: node:17.9.1
cache:
paths:
- node_modules/
before_script:
- npm install
script:
- npm run prod > front-build-report.json
artifacts:
when: on_failure
expose_as: 'front-build-report'
paths:
- front-build-report.json
allow_failure: false
needs:
- phpcs
- eslint
- stylelint
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
- if: $CI_COMMIT_BRANCH == "develop"
front-build:
stage: DepBuilds
image: node:17.9.1
before_script:
- npm install
cache:
paths:
- public/build/
script:
- npm run prod
artifacts:
expose_as: 'front-build'
paths:
- public/build
allow_failure: false
needs:
- front-build-test
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
- if: $CI_COMMIT_BRANCH == "develop"
composer-build:
stage: DepBuilds
image: $CI_REGISTRY/service-web-lab/ldc-web-images-docker/ldcweb-qa:php7.3-1.0
before_script:
- composer config gitlab-token.gitlab.com $CI_DEPLOY_USER $CI_DEPLOY_PASSWORD
cache:
paths:
- vendor/
script:
- composer install --no-dev --optimize-autoloader --classmap-authoritative
artifacts:
expose_as: 'vendor'
paths:
- vendor
allow_failure: false
needs:
- phpcs
- eslint
- stylelint
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
- if: $CI_COMMIT_BRANCH == "develop"
build-develop:
stage: Build
image: docker:20.10.16
services:
- name: docker:20.10.16-dind
alias: docker
variables:
IMAGE_TAG: $CI_REGISTRY_IMAGE/develop:$CI_COMMIT_SHORT_SHA
script:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
- docker build --tag $IMAGE_TAG .
- docker push $IMAGE_TAG
allow_failure: false
dependencies:
- front-build
- composer-build
needs:
- front-build
- composer-build
rules:
- if: $CI_COMMIT_BRANCH == "develop"
deploy-develop:
stage: Deploy
image: debian:latest
before_script:
- 'command -v ssh-agent >/dev/null || ( apt-get update -y && apt-get install openssh-client -y )'
- eval $(ssh-agent -s)
- echo "$DEVELOP_SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add -
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
- ssh-keyscan $DEVELOP_IPADDRESS >> ~/.ssh/known_hosts
- chmod 644 ~/.ssh/known_hosts
variables:
DEST_FOLDER: Run/$CI_PROJECT_NAME/develop
IMAGE_TAG: $CI_REGISTRY_IMAGE/develop:$CI_COMMIT_SHORT_SHA
script:
- ssh $DEVELOP_SSH_USER@$DEVELOP_IPADDRESS "mkdir -p $DEST_FOLDER"
- scp .env.example $DEVELOP_SSH_USER@$DEVELOP_IPADDRESS:$DEST_FOLDER
- scp dev-docker-compose.yml $DEVELOP_SSH_USER@$DEVELOP_IPADDRESS:$DEST_FOLDER
- ssh $DEVELOP_SSH_USER@$DEVELOP_IPADDRESS "sh Admin/Scripts/Deploy.sh $CI_PROJECT_NAME develop $IMAGE_TAG $DBPRODNAME"
environment:
name: develop
url: https://$CI_PROJECT_NAME-develop.s-web.loc
on_stop: stop-develop
needs:
- build-develop
rules:
- if: $CI_COMMIT_BRANCH == "develop"
stop-develop:
stage: Deploy
image: debian:latest
before_script:
- 'command -v ssh-agent >/dev/null || ( apt-get update -y && apt-get install openssh-client -y )'
- eval $(ssh-agent -s)
- echo "$DEVELOP_SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add -
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
- ssh-keyscan $DEVELOP_IPADDRESS >> ~/.ssh/known_hosts
- chmod 644 ~/.ssh/known_hosts
- apt-get update -y && apt-get install curl -y
- curl --fail --show-error --location "https://github.com/genuinetools/reg/releases/download/v$REG_VERSION/reg-linux-amd64" --output ./reg
- echo "$REG_SHA256 ./reg" | sha256sum -c -
- chmod a+x ./reg
variables:
DEST_FOLDER: Run/$CI_PROJECT_NAME/develop
IMAGE_TAG: $CI_REGISTRY_IMAGE/develop:$CI_COMMIT_SHORT_SHA
REG_SHA256: ade837fc5224acd8c34732bf54a94f579b47851cc6a7fd5899a98386b782e228
REG_VERSION: 0.16.1
script:
- ssh $DEVELOP_SSH_USER@$DEVELOP_IPADDRESS "sh Admin/Scripts/DeployStop.sh $CI_PROJECT_NAME develop $DBPRODNAME"
- ./reg rm -d --auth-url $CI_REGISTRY -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $IMAGE_TAG
environment:
name: develop
action: stop
rules:
- if: $CI_COMMIT_BRANCH == "develop"
when: manual
build-review:
stage: Build
image: docker:20.10.16
services:
- name: docker:20.10.16-dind
alias: docker
variables:
IMAGE_TAG: $CI_REGISTRY_IMAGE/review:$CI_MERGE_REQUEST_IID
script:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
- docker build --tag $IMAGE_TAG .
- docker push $IMAGE_TAG
allow_failure: false
dependencies:
- front-build
- composer-build
needs:
- front-build
- composer-build
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
deploy-review:
stage: Deploy
image: debian:latest
before_script:
- 'command -v ssh-agent >/dev/null || ( apt-get update -y && apt-get install openssh-client -y )'
- eval $(ssh-agent -s)
- echo "$DEVELOP_SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add -
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
- ssh-keyscan $DEVELOP_IPADDRESS >> ~/.ssh/known_hosts
- chmod 644 ~/.ssh/known_hosts
variables:
DEST_FOLDER: Run/$CI_PROJECT_NAME/$CI_MERGE_REQUEST_IID
IMAGE_TAG: $CI_REGISTRY_IMAGE/review:$CI_MERGE_REQUEST_IID
script:
- ssh $DEVELOP_SSH_USER@$DEVELOP_IPADDRESS "mkdir -p $DEST_FOLDER"
- scp .env.example $DEVELOP_SSH_USER@$DEVELOP_IPADDRESS:$DEST_FOLDER
- scp dev-docker-compose.yml $DEVELOP_SSH_USER@$DEVELOP_IPADDRESS:$DEST_FOLDER
- ssh $DEVELOP_SSH_USER@$DEVELOP_IPADDRESS "sh Admin/Scripts/Deploy.sh $CI_PROJECT_NAME $CI_MERGE_REQUEST_IID $IMAGE_TAG $DBPRODNAME"
environment:
name: review-$CI_MERGE_REQUEST_IID
url: https://$CI_PROJECT_NAME-$CI_MERGE_REQUEST_IID.s-web.loc
on_stop: stop-review
needs:
- build-review
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
when: manual
stop-review:
stage: Deploy
image: debian:latest
before_script:
- 'command -v ssh-agent >/dev/null || ( apt-get update -y && apt-get install openssh-client -y )'
- eval $(ssh-agent -s)
- echo "$DEVELOP_SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add -
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
- ssh-keyscan $DEVELOP_IPADDRESS >> ~/.ssh/known_hosts
- chmod 644 ~/.ssh/known_hosts
- apt-get update -y && apt-get install curl -y
- curl --fail --show-error --location "https://github.com/genuinetools/reg/releases/download/v$REG_VERSION/reg-linux-amd64" --output ./reg
- echo "$REG_SHA256 ./reg" | sha256sum -c -
- chmod a+x ./reg
variables:
DEST_FOLDER: Run/$CI_PROJECT_NAME/$CI_MERGE_REQUEST_IID
IMAGE_TAG: $CI_REGISTRY_IMAGE/review:$CI_MERGE_REQUEST_IID
REG_SHA256: ade837fc5224acd8c34732bf54a94f579b47851cc6a7fd5899a98386b782e228
REG_VERSION: 0.16.1
script:
- ssh $DEVELOP_SSH_USER@$DEVELOP_IPADDRESS "sh Admin/Scripts/DeployStop.sh $CI_PROJECT_NAME $CI_MERGE_REQUEST_IID $DBPRODNAME"
- ./reg rm -d --auth-url $CI_REGISTRY -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $IMAGE_TAG
environment:
name: review-$CI_MERGE_REQUEST_IID
action: stop
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
when: manual
- lint
- security
- build
- test
- deploy

View file

@ -1,4 +1,4 @@
FROM registry.gitlab.com/service-web-lab/ldc-web-images-docker/ldcweb-production:php7.3.0
COPY --chown=noroot:noroot . /app/srcs
COPY --chown=noroot:noroot ./public/build /app/srcs/public/build
COPY --chown=noroot:noroot ./vendor /app/srcs/vendor
FROM registry.s-web.fr/ldc-web/projets/ldc-web-images-docker/ldcweb-production-7.3:latest
COPY . /app/srcs
COPY ./public/build /app/srcs/public/build
COPY ./vendor /app/srcs/vendor

View file

@ -20,8 +20,8 @@
"laravel/framework": "^8.83",
"laravel/tinker": "^2.5",
"laravel/ui": "^3.4",
"ldc/web-admin-secure-laravel": "1.0.1",
"ldc/web-status-checker-laravel": "1.0.3",
"ldc/web-admin-secure-laravel": "^1.0",
"ldc/web-status-checker-laravel": "^1.0",
"mews/purifier": "^3.3",
"propaganistas/laravel-phone": "^4.4",
"sentry/sentry-laravel": "^3.1",
@ -77,14 +77,17 @@
"sort-packages": true,
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
}
},
"gitlab-domains": [
"lab.s-web.fr"
]
},
"minimum-stability": "dev",
"prefer-stable": true,
"repositories": {
"gitlab.com/16669037": {
"lab.s-web.fr/23": {
"type": "composer",
"url": "https://gitlab.com/api/v4/group/16669037/-/packages/composer/packages.json"
"url": "https://lab.s-web.fr/api/v4/group/23/-/packages/composer/packages.json"
}
}
}

14
composer.lock generated
View file

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "9256c04c28d5e4644fcd2c1384db3635",
"content-hash": "27c934032c52c408899d0fa51301aecb",
"packages": [
{
"name": "asm89/stack-cors",
@ -2251,12 +2251,12 @@
"version": "1.0.1",
"source": {
"type": "git",
"url": "https://gitlab.com/service-web-lab/ldc-web-admin-secure-laravel.git",
"url": "https://lab.s-web.fr/ldc-web/projets/ldc-web-admin-secure-laravel.git",
"reference": "c538f5d349b119ac64cb62b33e6368bef6be90bc"
},
"dist": {
"type": "zip",
"url": "https://gitlab.com/api/v4/projects/37314651/packages/composer/archives/ldc/web-admin-secure-laravel.zip?sha=c538f5d349b119ac64cb62b33e6368bef6be90bc",
"url": "https://lab.s-web.fr/api/v4/projects/20/packages/composer/archives/ldc/web-admin-secure-laravel.zip?sha=c538f5d349b119ac64cb62b33e6368bef6be90bc",
"reference": "c538f5d349b119ac64cb62b33e6368bef6be90bc",
"shasum": ""
},
@ -2315,12 +2315,12 @@
"version": "1.0.2",
"source": {
"type": "git",
"url": "https://gitlab.com/service-web-lab/ldc-web-status-checker.git",
"url": "https://lab.s-web.fr/ldc-web/projets/ldc-web-status-checker.git",
"reference": "70a4f96a272f42f9caaf8f614190a3e061273bc8"
},
"dist": {
"type": "zip",
"url": "https://gitlab.com/api/v4/projects/37071268/packages/composer/archives/ldc/web-status-checker.zip?sha=70a4f96a272f42f9caaf8f614190a3e061273bc8",
"url": "https://lab.s-web.fr/api/v4/projects/21/packages/composer/archives/ldc/web-status-checker.zip?sha=70a4f96a272f42f9caaf8f614190a3e061273bc8",
"reference": "70a4f96a272f42f9caaf8f614190a3e061273bc8",
"shasum": ""
},
@ -2360,12 +2360,12 @@
"version": "1.0.3",
"source": {
"type": "git",
"url": "https://gitlab.com/service-web-lab/ldc-web-status-checker-laravel.git",
"url": "https://lab.s-web.fr/ldc-web/projets/ldc-web-status-checker-laravel.git",
"reference": "32965e7425060c4167b40e5c0868c438ea94c14f"
},
"dist": {
"type": "zip",
"url": "https://gitlab.com/api/v4/projects/37071488/packages/composer/archives/ldc/web-status-checker-laravel.zip?sha=32965e7425060c4167b40e5c0868c438ea94c14f",
"url": "https://lab.s-web.fr/api/v4/projects/22/packages/composer/archives/ldc/web-status-checker-laravel.zip?sha=32965e7425060c4167b40e5c0868c438ea94c14f",
"reference": "32965e7425060c4167b40e5c0868c438ea94c14f",
"shasum": ""
},

View file

@ -1,33 +0,0 @@
version: '3.3'
services:
apachephp:
restart: always
image: $IMAGE
environment:
- PROJECT=$PROJECT
- SERVERNAME=$SERVERNAME
- DOCUMENTROOT=srcs/public
volumes:
- ./.env:/app/srcs/.env
- ./storage:/app/srcs/storage
- ./logs:/app/logs
- ./tmp:/app/tmp
labels:
- "traefik.enable=true"
- "traefik.http.routers.${PROJECT}-${COMMITSHA}-secure.entrypoints=websecure"
- "traefik.http.routers.${PROJECT}-${COMMITSHA}-secure.rule=Host(`${SERVERNAME}`)"
- "traefik.http.routers.${PROJECT}-${COMMITSHA}-secure.tls=true"
- "traefik.http.routers.${PROJECT}-${COMMITSHA}-secure.service=apache-php-${PROJECT}-${COMMITSHA}"
- "traefik.http.services.apache-php-${PROJECT}-${COMMITSHA}.loadbalancer.server.port=80"
- "traefik.http.routers.xdebug-${PROJECT}-${COMMITSHA}.entrypoints=xdebug"
- "traefik.http.routers.xdebug-${PROJECT}-${COMMITSHA}.rule=Host(`xdebug-${SERVERNAME}`)"
- "traefik.http.routers.xdebug-${PROJECT}-${COMMITSHA}.service=xdebug-${PROJECT}-${COMMITSHA}"
- "traefik.http.services.xdebug-${PROJECT}-${COMMITSHA}.loadbalancer.server.port=9003"
networks:
- ldcweb-dev-stack-network
networks:
ldcweb-dev-stack-network:
external: true

134
manifest.yaml Normal file
View file

@ -0,0 +1,134 @@
---
apiVersion: v1
kind: Namespace
metadata:
name: $CI_PROJECT_PATH_SLUG
---
apiVersion: v1
kind: ConfigMap
metadata:
name: ${CI_PROJECT_PATH_SLUG}-config-map
data:
APP_NAME: "poc-oe-wdmr"
APP_ENV: "dev"
APP_KEY: "base64:Juxmv7LhkCAkxyhw/8J4dPdnTZbVJkyvRG8jIMxqBZA="
APP_DEBUG: "true"
APP_URL: ""
ASSET_URL: "storage/"
LOG_CHANNEL: "stack"
LOG_DEPRECATIONS_CHANNEL: "null"
LOG_LEVEL: "debug"
DB_CONNECTION: "mysql"
DB_HOST: "mariadb-service.common-services"
DB_PORT: "3306"
DB_DATABASE: "poc-oe-wdmr"
DB_USERNAME: "poc-oe-wdmr"
DB_PASSWORD: "poc-oe-wdmr"
BROADCAST_DRIVER: "log"
CACHE_DRIVER: "file"
FILESYSTEM_DISK: "local"
QUEUE_CONNECTION: "sync"
SESSION_DRIVER: "file"
SESSION_LIFETIME: "120"
MAIL_MAILER: "smtp"
MAIL_HOST: ""
MAIL_PORT: ""
MAIL_USERNAME: ""
MAIL_PASSWORD: ""
MAIL_ENCRYPTION: "null"
MAIL_FROM_ADDRESS: ""
MAIL_FROM_NAME: "poc-oe-wdmr"
LDC_STATUS_CHECKER_API_KEY: "MY_KEY"
LDC_STATUS_CHECKER_UUID: "UUID_PROJECT"
LDC_WEB_API_KEY: "MY_KEY"
GOOGLE_MAPS_KEY: ""
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: ${CI_PROJECT_PATH_SLUG}-pvc-storage
spec:
storageClassName: "csi-cinder-classic"
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: ${CI_PROJECT_PATH_SLUG}-deployment
spec:
replicas: 1
selector:
matchLabels:
app: ${CI_PROJECT_PATH_SLUG}-app
template:
metadata:
labels:
app: ${CI_PROJECT_PATH_SLUG}-app
spec:
containers:
- name: ${CI_PROJECT_PATH_SLUG}-container
image: $IMAGE_TAG
envFrom:
- configMapRef:
name: ${CI_PROJECT_PATH_SLUG}-config-map
volumeMounts:
- name: storage
mountPath: /app/srcs/storage/app/public
imagePullSecrets:
- name: docker-registry-credentials
volumes:
- name: storage
persistentVolumeClaim:
claimName: ${CI_PROJECT_PATH_SLUG}-pvc-storage
---
apiVersion: v1
kind: Service
metadata:
name: ${CI_PROJECT_PATH_SLUG}-service
spec:
selector:
app: ${CI_PROJECT_PATH_SLUG}-app
ports:
- port: 80
targetPort: 8080
---
apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute
metadata:
name: ${CI_PROJECT_PATH_SLUG}-ingress-route
spec:
entryPoints:
- web
- websecure
routes:
- match: Host(`$DOMAIN`)
kind: Rule
services:
- name: ${CI_PROJECT_PATH_SLUG}-service
port: 80
tls:
secretName: $DOMAIN
---
apiVersion: cert-manager.io/v1
kind: Certificate
metadata:
name: $DOMAIN
spec:
dnsNames:
- $DOMAIN
secretName: $DOMAIN
issuerRef:
name: letsencrypt-staging-dns01
kind: ClusterIssuer