Skip to content
Snippets Groups Projects
Commit 51672af5 authored by Nhan Luong's avatar Nhan Luong :speech_balloon:
Browse files

Merge branch 'ci' into 'main'

Configure CI/CD pipeline

See merge request !10
parents d8a5d01e 236effdd
No related branches found
No related tags found
1 merge request!10Configure CI/CD pipeline
version: '3'
services: services:
playground-be: playground-be:
command: yarn dev -L command: yarn dev -L
volumes:
- .:/usr/src/playground-be
upload: upload:
command: npm start command: npm start
volumes:
- ./upload:/usr/src/upload
- /usr/src/upload/node_modules/
version: '3'
services: services:
playground-be: playground-be:
command: yarn dev -L command: yarn start
upload: upload:
command: npm run prod command: npm run prod
version: '3'
services: services:
playground-be: playground-be:
container_name: playground-be-test
command: yarn test command: yarn test
volumes:
- .:/usr/src/playground-be
# upload/Dockerfile
version: '3'
services: services:
playground-be: playground-be:
container_name: ${ENV:-dev}-playground-be
build: . build: .
image: playground-be image: boschvn/playground-be:${IMAGE_TAG:-latest}
ports: ports:
- '${PORT}:${PORT}' - '${PORT}:${PORT}'
depends_on: depends_on:
- playground-db - playground-db
- upload - upload
volumes:
- .:/usr/src/playground-be
networks: networks:
- node-network - node-network
restart: always
playground-db: playground-db:
container_name: ${ENV:-dev}-playground-db
image: mongo:4.4.6-bionic image: mongo:4.4.6-bionic
ports: ports:
- '${MONGO_EXPOSE_PORT}:27017' - '${MONGO_EXPOSE_PORT}:27017'
...@@ -23,24 +21,24 @@ services: ...@@ -23,24 +21,24 @@ services:
- dbdata:/data/db - dbdata:/data/db
networks: networks:
- node-network - node-network
restart: always
upload: upload:
container_name: ${ENV:-dev}-upload
build: ./upload/ build: ./upload/
image: upload image: boschvn/upload:${IMAGE_TAG:-latest}
ports: ports:
- '${UPLOAD_PORT}:${UPLOAD_PORT}' - '${UPLOAD_PORT}:${UPLOAD_PORT}'
volumes: volumes:
- ./upload:/usr/src/upload
- /usr/src/upload/node_modules/
- '${UPLOAD_PATH}:/usr/src/upload/data' - '${UPLOAD_PATH}:/usr/src/upload/data'
networks: networks:
- node-network - node-network
restart: always
volumes: volumes:
dbdata: dbdata:
networks: networks:
node-network: node-network:
driver: bridge driver: bridge
...@@ -37,7 +37,10 @@ if [ ! -d "$UPLOAD_PATH" ]; then ...@@ -37,7 +37,10 @@ if [ ! -d "$UPLOAD_PATH" ]; then
fi fi
# Replace env file to upload directory # Replace env file to upload directory
cp .env ./upload/ -f if ! cp .env ./upload/ -f; then
echo "Failed to copy .env file to ./upload/"
exit 1
fi
# Set permissions for the directory # Set permissions for the directory
echo "Setting permissions for $UPLOAD_PATH" echo "Setting permissions for $UPLOAD_PATH"
...@@ -48,23 +51,41 @@ sudo chmod -R 775 "$UPLOAD_PATH" ...@@ -48,23 +51,41 @@ sudo chmod -R 775 "$UPLOAD_PATH"
DOCKER_COMMAND="" DOCKER_COMMAND=""
NO_CACHE="" NO_CACHE=""
DETACH="" DETACH=""
BUILD=""
# Check for --no-cache argument # Check for arguments
for arg in "$@" for arg in "$@"
do do
if [ "$arg" == "--no-cache" ]; then case $arg in
NO_CACHE="--no-cache" --no-cache)
fi NO_CACHE="--no-cache"
if [ "$arg" == "-d" ]; then shift
DETACH="-d" ;;
fi -d)
DETACH="-d"
shift
;;
--build)
BUILD="--build"
shift
;;
-prod)
ENV_SUFFIX="prod"
shift
;;
*)
# Handle unexpected arguments
echo "Unknown argument: $arg"
exit 1
;;
esac
done done
# Determine the command to run based on the argument # Determine the Docker Compose command based on the -prod flag
if [ "$1" == "-prod" ]; then if [ "$ENV_SUFFIX" == "prod" ]; then
DOCKER_COMMAND="docker compose -f docker-compose.yml -f docker-compose.prod.yml up --build $NO_CACHE $DETACH" DOCKER_COMMAND="docker compose -p ${ENV}-playground-be -f docker-compose.yml -f docker-compose.prod.yml up $BUILD $NO_CACHE $DETACH"
else else
DOCKER_COMMAND="docker compose -f docker-compose.yml -f docker-compose.dev.yml up --build $NO_CACHE $DETACH" DOCKER_COMMAND="docker compose -p ${ENV}-playground-be -f docker-compose.yml -f docker-compose.dev.yml up $BUILD $NO_CACHE $DETACH"
fi fi
# Run Docker Compose # Run Docker Compose
......
...@@ -12,4 +12,3 @@ USER node ...@@ -12,4 +12,3 @@ USER node
RUN npm install RUN npm install
COPY --chown=node:node . . COPY --chown=node:node . .
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment