Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Commit 5fd25fb

Browse files
committed
Docker and circleci
1 parent 8219501 commit 5fd25fb

File tree

7 files changed

+146
-4
lines changed

7 files changed

+146
-4
lines changed

.circleci/config.yml

+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
version: 2
2+
defaults: &defaults
3+
docker:
4+
- image: circleci/python:2.7-stretch-browsers
5+
install_dependency: &install_dependency
6+
name: Installation of build and deployment dependencies.
7+
command: |
8+
sudo apt install jq
9+
sudo pip install awscli --upgrade
10+
sudo pip install docker-compose
11+
install_deploysuite: &install_deploysuite
12+
name: Installation of install_deploysuite.
13+
command: |
14+
git clone --branch v1.4.2 https://github.com/topcoder-platform/tc-deploy-scripts ../buildscript
15+
cp ./../buildscript/master_deploy.sh .
16+
cp ./../buildscript/buildenv.sh .
17+
cp ./../buildscript/awsconfiguration.sh .
18+
restore_cache_settings_for_build: &restore_cache_settings_for_build
19+
key: docker-node-modules-{{ checksum "package-lock.json" }}
20+
21+
save_cache_settings: &save_cache_settings
22+
key: docker-node-modules-{{ checksum "package-lock.json" }}
23+
paths:
24+
- node_modules
25+
26+
builddeploy_steps: &builddeploy_steps
27+
- checkout
28+
- setup_remote_docker
29+
- run: *install_dependency
30+
- run: *install_deploysuite
31+
- restore_cache: *restore_cache_settings_for_build
32+
- run:
33+
command: |
34+
./awsconfiguration.sh $DEPLOY_ENV
35+
source awsenvconf
36+
./buildenv.sh -e $DEPLOY_ENV -b ${LOGICAL_ENV}-${APPNAME}-buildvar
37+
- run:
38+
command: |
39+
source buildenvvar
40+
./build.sh ${APPNAME}
41+
- save_cache: *save_cache_settings
42+
- deploy:
43+
name: Running MasterScript.
44+
command: |
45+
source awsenvconf
46+
./buildenv.sh -e $DEPLOY_ENV -b ${LOGICAL_ENV}-${APPNAME}-deployvar
47+
source buildenvvar
48+
./master_deploy.sh -d ECS -e $DEPLOY_ENV -t latest -s ${LOGICAL_ENV}-global-appvar,${LOGICAL_ENV}-${APPNAME}-appvar -i ${APPNAME}
49+
jobs:
50+
# Build & Deploy against development backend
51+
"build-dev":
52+
<<: *defaults
53+
environment:
54+
DEPLOY_ENV: "DEV"
55+
LOGICAL_ENV: "dev"
56+
APPNAME: "micro-frontends-frame"
57+
steps: *builddeploy_steps
58+
59+
"build-prod":
60+
<<: *defaults
61+
environment:
62+
DEPLOY_ENV: "PROD"
63+
LOGICAL_ENV: "prod"
64+
APPNAME: "micro-frontends-frame"
65+
steps: *builddeploy_steps
66+
67+
workflows:
68+
version: 2
69+
build:
70+
jobs:
71+
# Development builds are executed on "develop" branch only.
72+
- "build-dev":
73+
context: org-global
74+
filters:
75+
branches:
76+
only:
77+
- dev
78+
79+
# Production builds are exectuted only on tagged commits to the
80+
# master branch.
81+
- "build-prod":
82+
context: org-global
83+
filters:
84+
branches:
85+
only: master

build.sh

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/bin/bash
2+
set -eo pipefail
3+
APP_NAME=$1
4+
UPDATE_CACHE=""
5+
6+
docker build -f docker/Dockerfile -t $APP_NAME:latest \
7+
--build-arg APPMODE=$APPMODE \
8+
--build-arg APPENV=$APPENV .
9+
10+
docker create --name app $APP_NAME:latest
11+
12+
if [ -d node_modules ]
13+
then
14+
mv package-lock.json old-package-lock.json
15+
docker cp app:/$APP_NAME/package-lock.json package-lock.json
16+
set +eo pipefail
17+
UPDATE_CACHE=$(cmp package-lock.json old-package-lock.json)
18+
set -eo pipefail
19+
else
20+
UPDATE_CACHE=1
21+
fi
22+
23+
if [ "$UPDATE_CACHE" == 1 ]
24+
then
25+
docker cp app:/$APP_NAME/node_modules .
26+
fi

config/development.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,4 @@
44
"@topcoder/micro-frontends-react-app": "https://www.topcoder-dev.com/topcoder-micro-frontends-react-app.js",
55
"@topcoder/micro-frontends-angular-app": "https://www.topcoder-dev.com/main.js"
66
}
7-
}
8-
s
7+
}

docker/Dockerfile

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Use the base image with Node.js
2+
FROM node:latest
3+
4+
ARG APPMODE
5+
ARG APPENV
6+
7+
ENV APPMODE=$APPMODE
8+
ENV APPENV=$APPENV
9+
10+
# Copy the current directory into the Docker image
11+
COPY . /micro-frontends-frame
12+
13+
# Set working directory for future use
14+
WORKDIR /micro-frontends-frame
15+
16+
# Install the dependencies from package.json
17+
RUN npm install
18+
19+
RUN npm build
20+
21+
CMD npm start

docker/docker-compose.yml

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
version: '3'
2+
services:
3+
micro-frontends-frame:
4+
image: micro-frontends-frame:latest
5+
build:
6+
context: ../
7+
dockerfile: docker/Dockerfile
8+
env_file:
9+
- api.env
10+
network_mode: "host"

docker/sample.api.env

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
AWS_ACCESS_KEY_ID=<AWS Access Key ID>
2+
AWS_SECRET_ACCESS_KEY=<AWS Secret Access Key>

package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
"lint": "eslint src --ext js",
77
"test": "cross-env BABEL_ENV=test jest --passWithNoTests",
88
"format": "prettier --write \"./**\"",
9-
"build-dev": "webpack --mode=development --env.config=dev",
10-
"build-prod": "webpack --mode=production --env.config=prod"
9+
"build": "webpack --mode=${APPMODE:-development} --env.config=${APPENV:-dev}"
1110
},
1211
"devDependencies": {
1312
"@babel/core": "^7.7.4",

0 commit comments

Comments
 (0)