-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5d735a3
commit 1fa5f25
Showing
1 changed file
with
110 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,10 +5,15 @@ | |
``` | ||
ng new my-super-app | ||
``` | ||
--- | ||
|
||
Pour installer et générer le fichier de configuation pour Eslint | ||
``` | ||
ng lint | ||
``` | ||
|
||
--- | ||
|
||
On créé un nouveau dépot gitlab (Sans readme.md) et on rajoute le remote dans l'application. | ||
``` | ||
Push an existing Git repository | ||
|
@@ -18,21 +23,34 @@ git remote add origin [email protected]:becode/my-web-app.git | |
git push --set-upstream origin --all | ||
git push --set-upstream origin --tags | ||
``` | ||
--- | ||
|
||
## Création du pipeline | ||
Cette fois nous allons créer un pipeline en 4 étapes qui auront une ou plusieurs tâches. | ||
|
||
- dependencies : Installation des dépendances NPM | ||
- quality : Test unitaire et lint | ||
- assemble : Compilation de l'application et push sur docker | ||
- build : Compilation de l'application et push sur docker | ||
- deploy : Deployement sur un serveur avec docker | ||
|
||
--- | ||
|
||
```yaml | ||
stages: | ||
- dependencies | ||
- quality | ||
- build | ||
- deploy | ||
``` | ||
--- | ||
## Paramètre par défaut | ||
```yaml | ||
default: | ||
interruptible: true | ||
image: trion/ng-cli-karma:latest | ||
image: trion/ng-cli-karma:17.1.3 | ||
tags: | ||
- docker | ||
cache: | ||
|
@@ -41,71 +59,111 @@ default: | |
- package.json | ||
paths: | ||
- node_modules | ||
``` | ||
--- | ||
stages: | ||
- dependencies | ||
- quality | ||
- assemble | ||
- deploy | ||
## Installation des dépendances | ||
```yaml | ||
install: | ||
stage: dependencies | ||
before_script: | ||
# Install dependencies | ||
- npm ci --prefer-offline | ||
script: | ||
- ng build | ||
- npm ci --prefer-offline | ||
``` | ||
--- | ||
## lint | ||
```yaml | ||
lint: | ||
stage: quality | ||
needs: ["install"] | ||
script: | ||
- ng lint | ||
``` | ||
--- | ||
|
||
## test | ||
```yaml | ||
test: | ||
stage: quality | ||
needs: ["lint"] | ||
needs: ["install"] | ||
script: | ||
- ng test --watch=false | ||
``` | ||
--- | ||
## Angular Build | ||
```yaml | ||
ng_build: | ||
stage: build | ||
needs: ["test", "lint"] | ||
artifacts: | ||
paths: | ||
- $CI_PROJECT_DIR/dist | ||
script: | ||
- ng test --watch=false | ||
|
||
# assemble: | ||
# stage: assemble | ||
# needs: ["test", "lint"] | ||
# script: | ||
# - npm run build | ||
# artifacts: | ||
# paths: | ||
# - $CI_PROJECT_DIR/dist | ||
|
||
# .deploy: | ||
# stage: deploy | ||
# variables: | ||
# NODE_ENV: production | ||
# needs: ["assemble"] | ||
# before_script: | ||
# - echo "Deploying to $CI_ENVIRONMENT_NAME" | ||
|
||
# deploy-dev: | ||
# extends: .deploy | ||
# variables: | ||
# NODE_ENV: development | ||
# script: | ||
# - echo "Deploying to $CI_ENVIRONMENT_NAME" | ||
# - echo "Making actions to deploy to dev" | ||
# - echo "Deployed to $CI_ENVIRONMENT_NAME" | ||
|
||
# deploy-staging: | ||
# extends: .deploy | ||
# rules: | ||
# - when: manual | ||
# allow_failure: true | ||
# variables: | ||
# NODE_ENV: staging | ||
# script: | ||
# - echo "Deploying to $CI_ENVIRONMENT_NAME" | ||
# - echo "Making actions to deploy to staging" | ||
# - echo "Deployed to $CI_ENVIRONMENT_NAM | ||
- ng build --base-href /app/ | ||
``` | ||
--- | ||
## Docker build | ||
```yaml | ||
docker_build: | ||
stage: build | ||
image: docker | ||
needs: ["ng_build"] | ||
services: | ||
- name: docker:dind | ||
alias: docker | ||
variables: | ||
DOCKER_BUILDKIT: "1" | ||
DOCKER_DRIVER: overlay2 | ||
DOCKER_HOST: tcp://docker:2375 | ||
DOCKER_TLS_CERTDIR: "" | ||
script: | ||
- docker build -t $CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA | ||
-t $CI_REGISTRY_IMAGE/myapp:latest | ||
. | ||
- echo $CI_REGISTRY_PASSWORD | docker login -u $CI_REGISTRY_USER --password-stdin $CI_REGISTRY | ||
- docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA | ||
- docker push $CI_REGISTRY_IMAGE/myapp:latest | ||
environment: | ||
name: prod | ||
tags: | ||
- docker | ||
``` | ||
--- | ||
## deploy | ||
Il faut créer un nouveau runner. | ||
```yaml | ||
deploy_prod: | ||
needs: ["scan", "docker_build"] | ||
stage: deploy | ||
environment: prod | ||
variables: | ||
DOCKER_BUILDKIT: "1" | ||
DOCKER_DRIVER: overlay2 | ||
DOCKER_TLS_CERTDIR: "" | ||
before_script: | ||
- container_id=$(docker ps | grep $CI_REGISTRY_IMAGE | awk '{ print $1 }') | ||
- if [ -n "$container_id" ]; then docker stop $container_id; fi; | ||
script: | ||
- echo "Deploy Starting" | ||
- echo $CI_REGISTRY_PASSWORD | docker login -u $CI_REGISTRY_USER --password-stdin $CI_REGISTRY | ||
- docker run -d -p 80:80 $CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA | ||
- container_id=$(docker ps | grep $CI_REGISTRY_IMAGE | awk '{ print $1 }') | ||
- docker exec $container_id ls -la | ||
tags: | ||
- prod | ||
rules: | ||
- if: '$CI_COMMIT_BRANCH == "main"' | ||
when: manual | ||
``` | ||
--- |