Commit c52d945e authored by dangdoan's avatar dangdoan

add cicd

parent df2f50d3
Pipeline #12946 canceled with stages
NODE_ENV=development
\ No newline at end of file
image: node:15.1.0
stages: stages:
- build - build
- deploy
variables:
dist_output_path: build
build: build:
stage: build stage: build
before_script: before_script:
- echo "in build" - source ./env-param.sh
- export CI_REGISTRY_PW=$CI_REGISTRY_PW
- export CI_REGISTRY_USER=$CI_REGISTRY_USER
- echo "To release new docker image for development and staging, we use tag 'dev' only !!!"
- export tag=dev
- cicd_path=$(pwd)/cicd
script: script:
- echo "in script" - bash $cicd_path/build.sh
- echo "create image" only:
- sudo docker build -t nodejs-image:1.0 . - release
tags:
- runner-builder
deploy:
stage: deploy
before_script:
- source ./env-param.sh
- cicd_path=$(pwd)/cicd
- export CI_REGISTRY_PW=$CI_REGISTRY_PW
- export CI_REGISTRY_USER=$CI_REGISTRY_USER
- |
if [ ! -d $mount_data_folder ]; then
sudo mkdir $mount_data_folder
sudo chown -R gitlab-runner.gitlab-runner $mount_data_folder
fi
- |
if [ ! -d $mount_data_folder/$project_name ]; then
sudo mkdir $mount_data_folder/$project_name
sudo chown -R gitlab-runner.gitlab-runner $mount_data_folder/$project_name
fi
script:
- export tag=dev
- bash $cicd_path/deploy.sh
only:
- release
tags: tags:
- test-deploy-1 - asset-ci-cd
\ No newline at end of file
# fix##
\ No newline at end of file
### STAGE 1: RUN ###
FROM node:15.1.0 FROM node
RUN chmod 1777 /tmp
RUN mkdir /data
RUN apt-get update -y
RUN apt-get install -y libgdiplus
RUN apt-get install -y libreoffice
RUN apt-get install -y libfontconfig
RUN apt-get install -y phantomjs
ENV OPENSSL_CONF=/opt/openssl.cnf
WORKDIR /usr/src/app WORKDIR /usr/src/app
COPY package*.json ./ COPY package.json package-lock.json ./
RUN npm install RUN npm install
COPY . . COPY . .
EXPOSE 8081 RUN cp -r ./swagger/supports/* ./node_modules
ENTRYPOINT ["node", "swagger.js"]
\ No newline at end of file
#! /bin/bash
function cp_ad()
{
sourceCheck=$1;
desPath=$2;
defaultSourceCheck=$3;
if [[ -z $sourceCheck ]] || [[ -z $desPath ]]
then
echo "Source path or destination path is empty";
exit 1;
fi
for item in "$sourceCheck"/*
do
if [[ -d $item ]]
then
relativePath=$(echo ${item/$defaultSourceCheck/});
pathRm=$desPath$relativePath;
echo $pathRm;
rm -rf $pathRm;
cp_ad $item $desPath $defaultSourceCheck;
fi
relativePath=$(echo ${item/$defaultSourceCheck/});
pathRm=$desPath$relativePath;
echo $pathRm
rm -rf $pathRm
done
}
cp_ad $1 $2 $3;
cp -rf $1/* $2;
#! /bin/bash
function download_angular()
{
sourceCheck=$1;
if [[ -z $sourceCheck ]]
then
echo "Source path is empty";
exit 1;
fi
for item in "$sourceCheck"/*
do
if [[ -d $item ]]
then
download_angular $item;
fi
sed -i '/return this.httpClient.request<Blob>/!{p;d;};n;n;n;a\\t\tresponseType: \x27blob\x27 as \x27json\x27,' $item
echo $item;
done
}
download_angular $1;
#!/bin/bash
echo "Waiting for the application goes online..."
sleep 15
swaggerUrl="http://localhost:$port_mapping/swagger/v1/swagger.json"
api=$(curl $swaggerUrl)
status=$?
if test $status -ne 0
then
exit 1
fi
api=$(jq 'del(.components.securitySchemes)' <<<$api)
api=$(jq 'del(.security)' <<<$api)
echo $api > apiFinal.json
request='{"spec":{},"type":"CLIENT","lang":"typescript-angular"}'
request=$(jq --argfile apiFinal apiFinal.json '.spec = $apiFinal' <<<$request)
echo $request > ts.json
rm -rf client
java -jar CICD/swagger-codegen-cli.jar generate -i apiFinal.json -l typescript-angular -o client --additional-properties modelPropertyNaming=original
rm -rf ts.json;
rm -rf production_file;
rm -rf apiFinal.json;
temp_path=$(pwd);
mkdir production_file;
cp -r client/*.ts production_file/; cp -r client/api production_file/; cp -r client/model production_file/; rm -rf client; mv production_file client
bash CICD/swagger_download client
git clone --single-branch --branch $fe_model_branch "http://${GIT_USER}:${GIT_USER_PW}@$fe_git_address.git"
cd $fe_git_project_name
git pull origin $fe_model_branch;
bash $temp_path/CICD/cp_ad $temp_path/client $temp_path/$fe_git_project_name/src/app $temp_path/client
git add --all; git commit -m "Update model auto" --allow-empty; git push "http://${GIT_USER}:${GIT_USER_PW}@$fe_git_address.git" HEAD:$fe_model_branch
\ No newline at end of file
#!/bin/bash
echo $image_name:$tag
sudo docker build -t $image_name:$tag -f Dockerfile .
sudo docker logout registry.gitlab.com
echo "$CI_REGISTRY_PW" | sudo docker login registry.gitlab.com -u "$CI_REGISTRY_USER" --password-stdin
sudo docker push $image_name:$tag
\ No newline at end of file
#!/bin/bash
jq -r 'keys[] as $k | "\($k)=\(.[$k])"' $environment_json_path > .env
sed -i 's|PROJECT-NAME|'$project_name'|' docker-compose.yaml
sed -i 's|ENVIRONMENT-NAME|'$environment_name'|' docker-compose.yaml
sed -i 's|IMAGE-NAME|'$image_name'|' docker-compose.yaml
sed -i 's|IMAGE-TAG|'$tag'|' docker-compose.yaml
sed -i 's|P-MAPPING|'$port_mapping'|' docker-compose.yaml
sed -i 's|MOUNT-DATA-FOLDER|'$mount_data_folder'|' docker-compose.yaml
echo "$CI_REGISTRY_PW" | sudo docker login registry.gitlab.com -u "$CI_REGISTRY_USER" --password-stdin
sudo docker-compose down
sudo docker-compose pull
sudo docker-compose --env-file .env up -d
\ No newline at end of file
#!/bin/bash
if [ "$check" == "[tag]" ]; then
sed -i 's|#||g' Dockerfile
sudo docker build -t $image_name:$tag -f Dockerfile .
sudo docker logout registry.gitlab.com
echo "$CI_REGISTRY_PW" | sudo docker login registry.gitlab.com -u "$CI_REGISTRY_USER" --password-stdin
sudo docker push $image_name:$tag
sudo docker rmi $image_name:$tag
fi
version: '3.5'
services:
app:
container_name: ENVIRONMENT-NAME-PROJECT-NAME
image: IMAGE-NAME:IMAGE-TAG
volumes:
- MOUNT-DATA-FOLDER/PROJECT-NAME:/media
ports:
- P-MAPPING:3000
restart: unless-stopped
pull_policy: always
\ No newline at end of file
#!/bin/bash
export project_name="chinguyen_nodejs_managestudents"
export image_name="registry.gitlab.com/meusolutions/chinguyen_nodejs_managestudents"
export port_mapping="5000"
export environment_name="staging"
export mount_data_folder="/var/data"
Markdown is supported
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