Commit 5ea9ed3c authored by Jenkins's avatar Jenkins
Browse files

Merge commit '590de714'

parents a05bc124 590de714
Pipeline #15980 failed with stages
in 33 seconds
......@@ -44,3 +44,5 @@ testem.log
# System Files
.DS_Store
Thumbs.db
/jenkins_release
\ No newline at end of file
#!/bin/bash
#!/bin/sh
set -e
# Source env file
......@@ -8,54 +8,53 @@ SCRIPTNAME=`basename $SCRIPT`
. $SCRIPTDIR/env.sh
## Prompt nexus.alkante.com password if needed
#if [ -z "${NEXUS_USR}" ]; then
# echo -n "Enter nexus.alkante.com login: "
# read NEXUS_USR
#fi
#if [ -z "${NEXUS_PSW}" ]; then
# echo -n "password: "
# stty -echo
# IFS= read -r NEXUS_PSW
# stty echo
# printf '\n'
#fi
# Fix default env value if needed
[[ -z "${NEXUS_USR}" ]] && NEXUS_USR='jenkins'
[[ -z "${NEXUS_PSW}" ]] && NEXUS_PSW='password'
[[ -z "${NEXUS_EMAIL}" ]] && NEXUS_EMAIL='jenkins@alkante.com'
[[ -z "${REPO_NPM}" ]] && REPO_NPM='nexus.alkante.com/repository/npm'
echo "Create docker with ssh dir"
docker run \
-d \
--name $DOCKER_NAME \
-v "$SCRIPTDIR/../..":/home/node/app \
-w /home/node/app \
node:10-stretch \
sh -c 'while sleep 3600; do :; done'
# Run in daemon process
# Define the container name
# Mount this code in the container
# Define the default working directory
# Docker image used
# Command wait infinitly compatible with many docker image
echo "Modify user right"
docker exec \
$DOCKER_NAME \
/bin/bash -c "chown -R node:node /home/node/app;"
#[ -z "${NEXUS_EMAIL}" ] && NEXUS_EMAIL='jenkins@alkante.com'
#[ -z "${REPO_COMPOSER_DOMAIN}" ] && REPO_COMPOSER_DOMAIN='nexus.alkante.com'
#[ -z "${REPO_NPM}" ] && REPO_NPM='nexus.alkante.com/repository/npm'
echo -n "LOCAL_USER_ID=$(id -u)\nLOCAL_GROUP_ID=$(id -g)" > $SCRIPTDIR/docker-build/docker-compose.env;
# Create dockers
docker-compose -f $SCRIPTDIR/docker-build/docker-compose.yml build
docker-compose -f $SCRIPTDIR/docker-build/docker-compose.yml up -d
sleep 2 # Wait entrypoint run
# Exec
docker exec -u node:node -w /home/node/app $DOCKER_NAME /bin/bash -c ' \
docker exec --user node:node -w /home/node/app ${DOCKER_NAME}_build_web /bin/bash -c " \
set -e; \
export TOKEN=$(curl -s \
-H "Accept: application/json" \
-H "Content-Type:application/json" \
-X PUT \
-d '"'"'{"name":"'$NEXUS_USR'","password": "'$NEXUS_PSW'"}'"'"' \
https://'$REPO_NPM'/-/user/org.couchdb.user:'$NEXUS_USR' 2>&1 | grep -Po \
'"'"'(?<="token":")[^"]*'"'"'); \
echo Add repo : '$REPO_NPM'; \
npm set @alkante:registry "https://'$REPO_NPM'/"; \
npm set //'$REPO_NPM'/:_authToken=$TOKEN; \
sleep 1; \
npm install;'
# Reset user right
USER_ID=`id -u`
GROUP_ID=`id -g`
docker exec $DOCKER_NAME /bin/bash -c " \
chown -R $USER_ID:$GROUP_ID /home/node/app"
# Stop docker
docker rm -f $DOCKER_NAME
\ No newline at end of file
npm install;"
## Exec
#docker exec --user node:node -w /home/node/app ${DOCKER_NAME}_build_web /bin/bash -c ' \
# set -e; \
# export TOKEN=$(curl -s \
# -H "Accept: application/json" \
# -H "Content-Type:application/json" \
# -X PUT \
# -d '"'"'{"name":"'$NEXUS_USR'","password": "'$NEXUS_PSW'"}'"'"' \
# https://'$REPO_NPM'/-/user/org.couchdb.user:'$NEXUS_USR' 2>&1 | grep -Po \
# '"'"'(?<="token":")[^"]*'"'"'); \
# echo Add repo : '$REPO_NPM'; \
# npm set @alkante:registry "https://'$REPO_NPM'/"; \
# npm set //'$REPO_NPM'/:_authToken=$TOKEN; \
# sleep 1; \
# npm install;'
# Stop dockers
docker-compose -f $SCRIPTDIR/docker-build/docker-compose.yml down
......@@ -7,35 +7,18 @@ SCRIPTDIR=`dirname $SCRIPT`
SCRIPTNAME=`basename $SCRIPT`
. $SCRIPTDIR/env.sh
# Create docker
docker run \
-d \
--name $DOCKER_NAME \
-v "$SCRIPTDIR/../..":/home/node/app \
-w /home/node/app \
node:10-stretch \
sh -c 'while sleep 3600; do :; done'
# Run in daemon process
# Define the container name
# Mount this code in the container
# Define the default working directory
# Docker image used
# Command wait infinitly compatible with many docker image
echo -n "LOCAL_USER_ID=$(id -u)\nLOCAL_GROUP_ID=$(id -g)" > $SCRIPTDIR/docker-build/docker-compose.env;
# Modify user right
docker exec $DOCKER_NAME \
/bin/bash -c "chown -R node:node /home/node/app;"
# Create dockers
docker-compose -f $SCRIPTDIR/docker-build/docker-compose.yml build
docker-compose -f $SCRIPTDIR/docker-build/docker-compose.yml up -d
sleep 2 # Wait entrypoint run
# Exec
docker exec --user node:node $DOCKER_NAME /bin/bash -c " \
docker exec --user node:node -w /home/node/app ${DOCKER_NAME}_web /bin/bash -c " \
set -e; \
npm run lint;"
# Reset user right
USER_ID=`id -u`
GROUP_ID=`id -g`
docker exec $DOCKER_NAME /bin/bash -c " \
chown -R $USER_ID:$GROUP_ID /home/node/app"
# Stop docker
docker rm -f $DOCKER_NAME
# Stop dockers
docker-compose -f $SCRIPTDIR/docker-build/docker-compose.yml down
......@@ -7,35 +7,18 @@ SCRIPTDIR=`dirname $SCRIPT`
SCRIPTNAME=`basename $SCRIPT`
. $SCRIPTDIR/env.sh
# Create docker
docker run \
-d \
--name $DOCKER_NAME \
-v "$SCRIPTDIR/../..":/home/node/app \
-w /home/node/app \
node:10-stretch \
sh -c 'while sleep 3600; do :; done'
# Run in daemon process
# Define the container name
# Mount this code in the container
# Define the default working directory
# Docker image used
# Command wait infinitly compatible with many docker image
echo -n "LOCAL_USER_ID=$(id -u)\nLOCAL_GROUP_ID=$(id -g)" > $SCRIPTDIR/docker-build/docker-compose.env;
# Modify user right
docker exec $DOCKER_NAME \
/bin/bash -c "chown -R node:node /home/node/app;"
# Create dockers
docker-compose -f $SCRIPTDIR/docker-build/docker-compose.yml build
docker-compose -f $SCRIPTDIR/docker-build/docker-compose.yml up -d
sleep 2 # Wait entrypoint run
# Exec
docker exec --user node:node $DOCKER_NAME /bin/bash -c " \
docker exec --user node:node -w /home/node/app ${DOCKER_NAME}_build_web /bin/bash -c " \
set -e; \
npm run e2e;"
# Reset user right
USER_ID=`id -u`
GROUP_ID=`id -g`
docker exec $DOCKER_NAME /bin/bash -c " \
chown -R $USER_ID:$GROUP_ID /home/node/app"
# Stop docker
docker rm -f $DOCKER_NAME
# Stop dockers
docker-compose -f $SCRIPTDIR/docker-build/docker-compose.yml down
......@@ -7,35 +7,18 @@ SCRIPTDIR=`dirname $SCRIPT`
SCRIPTNAME=`basename $SCRIPT`
. $SCRIPTDIR/env.sh
# Create docker
docker run \
-d \
--name $DOCKER_NAME \
-v "$SCRIPTDIR/../..":/home/node/app \
-w /home/node/app \
node:10-stretch \
sh -c 'while sleep 3600; do :; done'
# Run in daemon process
# Define the container name
# Mount this code in the container
# Define the default working directory
# Docker image used
# Command wait infinitly compatible with many docker image
echo -n "LOCAL_USER_ID=$(id -u)\nLOCAL_GROUP_ID=$(id -g)" > $SCRIPTDIR/docker-build/docker-compose.env;
# Modify user right
docker exec $DOCKER_NAME \
/bin/bash -c "chown -R node:node /home/node/app;"
# Create dockers
docker-compose -f $SCRIPTDIR/docker-build/docker-compose.yml build
docker-compose -f $SCRIPTDIR/docker-build/docker-compose.yml up -d
sleep 2 # Wait entrypoint run
# Exec
docker exec --user node:node $DOCKER_NAME /bin/bash -c " \
docker exec --user node:node -w /home/node/app ${DOCKER_NAME}_build_web /bin/bash -c " \
set -e; \
npm run prod;"
# Reset user right
USER_ID=`id -u`
GROUP_ID=`id -g`
docker exec $DOCKER_NAME /bin/bash -c " \
chown -R $USER_ID:$GROUP_ID /home/node/app"
# Stop docker
docker rm -f $DOCKER_NAME
# Stop dockers
docker-compose -f $SCRIPTDIR/docker-build/docker-compose.yml down
......@@ -5,13 +5,13 @@ set -e
SCRIPT=`readlink -f $0`
SCRIPTDIR=`dirname $SCRIPT`
SCRIPTNAME=`basename $SCRIPT`
ROOTDIR="$SCRIPTDIR/../.."
COMMIT=`git rev-parse --short=8 HEAD`
DATE="`date '+%Y%m%dT%H%M'`"
. $SCRIPTDIR/env.sh
# Make release
mkdir -p jenkins_release/${PROJECT_NAME}
rm -rf $ROOTDIR/jenkins_release/
mkdir -p $ROOTDIR/jenkins_release/${PROJECT_NAME}
cp -r dist/ngpr_prodige_table_editeur/* jenkins_release/${PROJECT_NAME}/
cd jenkins_release
tar -czf ${PROJECT_NAME}_${COMMIT}_${DATE}.tar.gz ${PROJECT_NAME}
cp -r $ROOTDIR/dist/ngpr_prodige_table_editeur/* $ROOTDIR/jenkins_release/${PROJECT_NAME}/
......@@ -5,15 +5,24 @@ set -e
SCRIPT=`readlink -f $0`
SCRIPTDIR=`dirname $SCRIPT`
SCRIPTNAME=`basename $SCRIPT`
ROOTDIR="$SCRIPTDIR/../.."
COMMIT=`git rev-parse --short=8 HEAD`
DATE="`date '+%Y%m%dT%H%M'`"
. $SCRIPTDIR/env.sh
# Build docker
docker build -t ${PROJECT_NAME}:${COMMIT} -f cicd/build/docker/Dockerfile .
cd $ROOTDIR
docker build -t ${PROJECT_NAME}_web:${COMMIT} -f $ROOTDIR/cicd/build/docker-prod/web/Dockerfile .
# Save image
docker save ${PROJECT_NAME}:${COMMIT} | gzip > jenkins_release/${PROJECT_NAME}_${COMMIT}_${DATE}.docker
# Tag to latest
docker tag ${PROJECT_NAME}_web:${COMMIT} ${PROJECT_NAME}_web
# Clean docker
docker rmi -f ${PROJECT_NAME}:${COMMIT}
\ No newline at end of file
## Remove previous docker if exist
#mkdir -p $ROOTDIR/jenkins_release
#files=`find $ROOTDIR/jenkins_release -type f -name "*.docker" -print`
#if [ "${files}" ]; then
# rm $ROOTDIR/jenkins_release/*.docker
#fi
## Save image
#docker save ${PROJECT_NAME}_web:${COMMIT} | gzip > $ROOTDIR/jenkins_release/${PROJECT_NAME}_web_${COMMIT}_${DATE}.docker
......@@ -7,31 +7,42 @@ SCRIPTDIR=`dirname $SCRIPT`
SCRIPTNAME=`basename $SCRIPT`
. $SCRIPTDIR/env.sh
if [ ! "$(docker ps -q -f name=$DOCKER_NAME)" ]; then
if [ "$(docker ps -aq -f status=exited -f name=$DOCKER_NAME)" ]; then
# Clean docker
docker rm -f $DOCKER_NAME
fi
# Create docker
docker run \
-d \
--name $DOCKER_NAME \
-v "$SCRIPTDIR/../..":/home/node/app \
-u root \
-w / \
node:10-stretch \
sh -c 'while sleep 3600; do :; done'
fi
#if [ ! "$(docker ps -q -f name=$DOCKER_NAME)" ]; then
# if [ "$(docker ps -aq -f status=exited -f name=$DOCKER_NAME)" ]; then
# # Clean docker
# docker rm -f $DOCKER_NAME
# fi
# # Create docker
# docker run \
# -d \
# --name $DOCKER_NAME \
# -v "$SCRIPTDIR/../..":/home/node/app \
# -w /home/node/app \
# node:12-stretch \
# sh -c 'while sleep 3600; do :; done'
#fi
echo " Start 99_clean.sh"
# Reset user right
USER_ID=`id -u`
GROUP_ID=`id -g`
docker exec \
-u root \
-w / \
$DOCKER_NAME \
/bin/bash -c " \
chown -R $USER_ID:$GROUP_ID /home/node/app"
echo -n "LOCAL_USER_ID=$(id -u)\nLOCAL_GROUP_ID=$(id -g)" > $SCRIPTDIR/docker-build/docker-compose.env;
# Clean docker
docker rm -f $DOCKER_NAME
# Clean container gerenated
list="${DOCKER_NAME}_web ${DOCKER_NAME}_build_web "
for var in $list
do
if [ "$(docker ps -aq -f name=${var})" ]; then
echo " Clean container ${var}"
docker rm -f ${var}
fi
done
# Clean image gerenated
list="${DOCKER_NAME}_build_web"
for var in $list
do
if [ "$(docker images -q -f reference=${var})" ]; then
echo " Clean images ${var}"
docker rmi ${var}
fi
done
echo " End 99_clean.sh"
......@@ -2,10 +2,10 @@ pipeline {
agent any
options { disableConcurrentBuilds() }
stages {
stage('Fetch dependencies') {
environment {
NEXUS = credentials('Nexus')
}
stage('Fetch dependencies'){
//environment {
// NEXUS = credentials('Nexus')
//}
agent any
steps {
sh 'cicd/build/0_fetch-dependencies.sh'
......@@ -40,16 +40,11 @@ pipeline {
steps {
unstash 'jenkins_release'
sh 'cicd/build/6_make_docker.sh'
stash includes: 'jenkins_release/', name: 'jenkins_release'
//stash includes: 'jenkins_release/', name: 'jenkins_release'
}
}
}
post {
success {
unstash 'jenkins_release'
archiveArtifacts artifacts: 'jenkins_release/*.tar.gz', onlyIfSuccessful: true
archiveArtifacts artifacts: 'jenkins_release/*.docker', onlyIfSuccessful: true
}
always {
sh 'cicd/build/99_clean.sh'
}
......
# Build
## Exectue build process localy
The build step is a pipeline decribe in ```Jenkinsfile```.
The step a runned in order with all bash script as [number]_[script_name].sh
Exemple, run one by one :
```bash
sh ./0_fetch-dependencies.sh
sh ./1_lint.sh
sh ./3_build-prod.sh
sh ./5_make_release.sh
sh ./6_make_docker.sh
```
Now you can the docker you build with ```../test-prod/README.md```
If an error occur, use the ```99_clean.sh``` to clean all and revert rigths.
## Advanced
### Use nexus
To use nexus.alkante.com get composer and/or npm package, you need to uncomment lines with NEXUS, NEXUS_USR and NEXUS_PSW in file:
- ./0_fetch-dependencies.sh
- ./Jenkinsfile
### Run assetic
To run assetic, you need to uncomment "Make asset cache" step in :
- ./Jenkinsfile
\ No newline at end of file
/entrypoint-build
/docker-compose.env
version: '3.5'
services:
ngpr_prodige_table_editeur_build_web:
image: ngpr_prodige_table_editeur_build_web # Docker image name
container_name: ngpr_prodige_table_editeur_build_web # Docker container name
build: ./web # Build images with this ./Dockerfile
volumes:
- ../../..:/home/node/app # Mount this code sources (../..) in container
environment:
- TZ=Europe/Paris
env_file:
- ./docker-compose.env
ports:
- "4200:4200"
networks:
default:
name: ngpr_prodige_table_editeur_network
# https://hub.docker.com/
FROM node:12-stretch
# Disable npm analytics questions when npn install
ENV NG_CLI_ANALYTICS flase
# Create Working diretory
RUN mkdir -p /home/node/app && \
chown node:node /home/node/app
# Script entrypoint
COPY entrypoint-build /usr/local/bin/
RUN chmod a+x /usr/local/bin/entrypoint-build
#WORKDIR /home/node/app
#USER node:node
ENTRYPOINT ["/usr/local/bin/entrypoint-build"]
#!/bin/bash
set -e
echo " # fix uid and gid"
if [ -n "$LOCAL_USER_ID" ]
then
usermod -u $LOCAL_USER_ID node
fi
if [ -n "$LOCAL_GROUP_ID" ]
then
groupmod -g $LOCAL_GROUP_ID node
fi
#chown node:node /home/node/app
echo " # sleep infinity"
sleep infinity
\ No newline at end of file
......@@ -2,4 +2,4 @@ FROM nginx:1.17-alpine
# Copy src
COPY --chown=nginx:nginx jenkins_release/ngpr_prodige_table_editeur /home/www
COPY --chown=root:root cicd/build/docker/nginx.conf /etc/nginx/conf.d/default.conf
COPY --chown=root:root cicd/build/docker-prod/web/nginx.conf /etc/nginx/conf.d/default.conf
version: '3'
services:
web:
image: ngpr_prodige_table_editeur # Docker image name
container_name: ngpr_prodige_table_editeur # Docker container name
build: . # Build images with this ./Dockerfile
ports:
- "8080:80"
#!/bin/bash
PROJECT_NAME="ngpr_prodige_table_editeur"
DOCKER_NAME="${PROJECT_NAME}_build"
DOCKER_NAME="${PROJECT_NAME}"
......@@ -6,8 +6,6 @@
- [Overview](#overview)
- [Start developpement](#start-developpement)
- [Stop developpement](#stop-developpement)
- [Tricks](#tricks)
- [npm login non interactive](#npm-login-non-interactive)
- [General Docker commands](#general-docker-commands)
- [Advanced Docker commands](#advanced-docker-commands)
- [Clean commands](#clean-commands)
......@@ -46,8 +44,6 @@ In an other terminal, connect as www-data to the dev container
docker exec --user node -w /home/node/app -it ngpr_prodige_table_editeur_dev_web bash
```
Configure the ```./src/env.js```
In container
```bash
# Install
......@@ -72,28 +68,6 @@ docker-compose down
docker rmi ngpr_prodige_table_editeur_dev_web
```
## Tricks
### npm login non interactive
```bash
# Fix default env value if needed
export NEXUS_USER='jenkins'
export NEXUS_PASSWORD='password'
export NEXUS_EMAIL='jenkins@alkante.com'
export REPO_NPM='https://nexus.alkante.com/repository/npm'
export TOKEN=$(curl -s \
-H "Accept: application/json" \
-H "Content-Type:application/json" \
-X PUT --data '{"name": "'$NEXUS_USER'", "password": "'$NEXUS_PASSWORD'"}' \
$REPO_NPM/-/user/org.couchdb.user:$NEXUS_USER 2>&1 | grep -Po \
'(?<="token":")[^"]*')
npm set registry "http://$REPO_NPM"
npm set //$REPO_NPM/:_authToken $TOKEN
```
## General Docker commands
| Description | Commandes |
......
version: '3'
version: '3.5'
services:
web:
ngpr_prodige_table_editeur_dev_web:
image: ngpr_prodige_table_editeur_dev_web # Docker image name
container_name: ngpr_prodige_table_editeur_dev_web # Docker container name
build: . # Build images with this ./Dockerfile
build: ./web # Build images with this ./Dockerfile
volumes:
- $SSH_AUTH_SOCK:/ssh-agent
- ~/.ssh/known_hosts:/home/node/.ssh/known_hosts
- ../..:/home/node/app # Mount this code sources (../..) in container
environment:
- TZ=Europe/Paris
env_file:
- ./docker-compose.env
environment:
- SSH_AUTH_SOCK=/ssh-agent
ports:
- "4200:4200"
networks:
default:
name: ngpr_prodige_table_editeur_network
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment