feat(CI): Adding CI deployment script
This commit is contained in:
27
.gitlab-ci.yml
Normal file
27
.gitlab-ci.yml
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
stages:
|
||||||
|
- build
|
||||||
|
- deploy
|
||||||
|
|
||||||
|
variables:
|
||||||
|
PIPELINE_WORK_DIR: "./"
|
||||||
|
DOCKERFILE_PATH: "./"
|
||||||
|
API_CFG: "./config/default.json"
|
||||||
|
CONTAINER_NAME: "enruta-etaapi"
|
||||||
|
PUBLIC_PORT: 7001
|
||||||
|
PRIVATE_PORT: 3000
|
||||||
|
|
||||||
|
build-job:
|
||||||
|
stage: build
|
||||||
|
script:
|
||||||
|
- . ./scripts/ci_functions.sh
|
||||||
|
- build_docker $CONTAINER_NAME
|
||||||
|
only:
|
||||||
|
- master
|
||||||
|
|
||||||
|
deploy-job:
|
||||||
|
stage: deploy
|
||||||
|
script:
|
||||||
|
- . ./scripts/ci_functions.sh
|
||||||
|
- deploy
|
||||||
|
only:
|
||||||
|
- master
|
||||||
10
Dockerfile
10
Dockerfile
@@ -1,20 +1,20 @@
|
|||||||
# Use an official Python runtime as a parent image
|
# Use an official Python runtime as a parent image
|
||||||
FROM node:14-alpine
|
FROM node:18-alpine
|
||||||
|
|
||||||
# Set the working directory to /app
|
# Set the working directory to /app
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
# Copy the current directory contents into the container at /app
|
# Copy the current directory contents into the container at /app
|
||||||
COPY sections /app/sections
|
|
||||||
COPY lib /app/lib
|
|
||||||
COPY config /app/config
|
COPY config /app/config
|
||||||
|
COPY lib /app/lib
|
||||||
|
COPY sections /app/sections
|
||||||
COPY index.js /app
|
COPY index.js /app
|
||||||
COPY package.json /app
|
COPY package.json /app
|
||||||
COPY dotenv /app/.env
|
COPY dotenv /app/.env
|
||||||
|
|
||||||
RUN npm install 2>/dev/null
|
RUN npm install --include=dev
|
||||||
|
|
||||||
EXPOSE 8080
|
EXPOSE 3000
|
||||||
|
|
||||||
ENV ROOT_PATH="/app"
|
ENV ROOT_PATH="/app"
|
||||||
|
|
||||||
|
|||||||
2
dotenv
2
dotenv
@@ -1,4 +1,4 @@
|
|||||||
SERVER_PORT=8080
|
SERVER_PORT=3000
|
||||||
ROOT_PATH=/home/josepablocb/Documents/Work/EnRuta/SysS/ETAAPI
|
ROOT_PATH=/home/josepablocb/Documents/Work/EnRuta/SysS/ETAAPI
|
||||||
API_CONFIG=config/apiConfig.json
|
API_CONFIG=config/apiConfig.json
|
||||||
############################
|
############################
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
"description": "ETA API",
|
"description": "ETA API",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "nodemon index.js",
|
"start": "node index.js",
|
||||||
"dev": "nodemon index.js"
|
"dev": "nodemon index.js"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
|
|||||||
45
scripts/ci_functions.sh
Executable file
45
scripts/ci_functions.sh
Executable file
@@ -0,0 +1,45 @@
|
|||||||
|
#! /bin/bash
|
||||||
|
|
||||||
|
# Requirements
|
||||||
|
# Docker: Node v18-alpine
|
||||||
|
function build_docker(){
|
||||||
|
if [[ $# -lt 1 ]]; then
|
||||||
|
echo $0 "[conatiner name]"
|
||||||
|
return -1
|
||||||
|
fi
|
||||||
|
CONTAINER_NAME=$1
|
||||||
|
|
||||||
|
set -x
|
||||||
|
docker rmi -f "$AWS_ECR_REPO/$CONTAINER_NAME"
|
||||||
|
docker buildx build --no-cache -t $AWS_ECR_REPO/$CONTAINER_NAME ./
|
||||||
|
set +x
|
||||||
|
}
|
||||||
|
|
||||||
|
function deploy_uservice(){
|
||||||
|
# CONTAINER NAME
|
||||||
|
# PUBLIC PORT
|
||||||
|
# PRIVATE PORT
|
||||||
|
# ECR REPO
|
||||||
|
if [[ $# -lt 4 ]]; then
|
||||||
|
echo "$0 [container_name] [public port] [private port] [ecr_repo]"
|
||||||
|
return -1
|
||||||
|
fi
|
||||||
|
container_name=$1
|
||||||
|
public_port=$2
|
||||||
|
private_port=$3
|
||||||
|
ecr_repo=$4
|
||||||
|
|
||||||
|
docker stop $container_name && docker rm $container_name
|
||||||
|
docker run -p"$public_port:$private_port" -d --restart unless-stopped --name $container_name $ecr_repo/$container_name:latest
|
||||||
|
}
|
||||||
|
|
||||||
|
function deploy_local(){
|
||||||
|
# docker login --username $AWS_ECR_USER --password $DOCKER_PWD $AWS_ECR_REPO
|
||||||
|
deploy_uservice $CONTAINER_NAME $PUBLIC_PORT $PRIVATE_PORT $AWS_ECR_REPO
|
||||||
|
}
|
||||||
|
|
||||||
|
function deploy(){
|
||||||
|
set -x
|
||||||
|
deploy_local
|
||||||
|
set +x
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user