-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrbc.sh
71 lines (58 loc) · 1.92 KB
/
rbc.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/bin/bash
# Project Information
REPOSITORY_URL="[email protected]:salhernandez/test-react.git"
PROJECT_NAME="test-react"
BRANCH_NAME="master"
NODE_VERSION_REACT_APP="latest"
# Default create-react-app port
LOCAL_PORT=5000
REACT_CONTAINER_PORT=3000
# Path to SSH RSA KEY
ID_RSA_PATH="/mnt/c/Users/Sal/.ssh/id_rsa_hernandezgsal"
BUILD_CACHE="--no-cache"
# ./run.sh -b <branch_name> -p <local_port> -c <react_container_port>
while getopts ":b:p:c:" arg; do
case $arg in
b) BRANCH_NAME=$OPTARG;;
p) LOCAL_PORT=$OPTARG;;
c) REACT_CONTAINER_PORT=$OPTARG;;
esac
done
IMAGE_NAME="${PROJECT_NAME}/${BRANCH_NAME}:latest"
# Add environment variable
export IMAGE_NAME=$IMAGE_NAME
echo "*****************************"
echo "--VARIABLES"
echo "*****************************"
echo Repository: $REPOSITORY_URL
echo Project: $PROJECT_NAME
echo Node Environment for React Application: $NODE_VERSION_REACT_APP
echo Local Port: $LOCAL_PORT
echo React Container Port: $REACT_CONTAINER_PORT
echo Branch: $BRANCH_NAME
echo Image to be created: $IMAGE_NAME
echo Path to RSA KEY: $ID_RSA_PATH
echo "*****************************"
echo "--START BUILD"
echo "*****************************"
# Build image
docker-compose build \
$BUILD_CACHE \
--build-arg BRANCH_NAME=$BRANCH_NAME \
--build-arg PROJECT_NAME=$PROJECT_NAME \
--build-arg REPOSITORY_URL=$REPOSITORY_URL \
--build-arg REACT_CONTAINER_PORT=$REACT_CONTAINER_PORT \
--build-arg NODE_VERSION_REACT_APP=$NODE_VERSION_REACT_APP \
--build-arg SSH_PRIVATE_KEY="$(cat ${ID_RSA_PATH})"
echo "*****************************"
echo "--END BUILD"
echo "*****************************"
echo "*****************************"
echo "--RUN IMAGE"
echo "*****************************"
# Run Container
# Bind local machine's port 3001 to container's port 3000
docker run -it --rm -p $LOCAL_PORT:$REACT_CONTAINER_PORT $IMAGE_NAME
echo "*****************************"
echo "--END OF SCRIPT"
echo "*****************************"