Skip to content

Commit a64f848

Browse files
committed
Refactor build scripts and Docker image
1 parent 40ee76e commit a64f848

File tree

4 files changed

+62
-36
lines changed

4 files changed

+62
-36
lines changed

ci-scripts/build.sh

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/bin/bash -x
2+
set -eu -o pipefail
3+
4+
#############################################################
5+
# Any function offered by this file assume that the path is #
6+
# located at the root of repository classroom-demo #
7+
#############################################################
8+
9+
# CI flags
10+
BUILD_FRONT=false
11+
BUILD_BACK=false
12+
13+
# Environment variables
14+
if [[ -n ${1:-} ]]; then
15+
case "${1:-}" in
16+
--build-front)
17+
BUILD_FRONT=true
18+
;;
19+
--build-back)
20+
BUILD_BACK=true
21+
;;
22+
*)
23+
echo "Unrecognized method $1"
24+
exit 1
25+
;;
26+
esac
27+
else
28+
echo "Must provide a method to execute as first parameter when calling the script"
29+
exit 1
30+
fi
31+
32+
# -------------
33+
# Build front
34+
# -------------
35+
if [[ "${BUILD_FRONT}" == true ]]; then
36+
rm -rf src/main/resources/static/*
37+
cd src/angular/frontend
38+
npm install --force
39+
npx ng build --output-path ../../../src/main/resources/static
40+
fi
41+
42+
# -------------
43+
# Build back
44+
# -------------
45+
if [[ "${BUILD_BACK}" == true ]]; then
46+
mvn clean compile package
47+
fi

docker/Dockerfile

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,16 @@
1-
FROM node:lts-alpine3.12 as frontend-build
2-
3-
WORKDIR /classroom-demo
4-
5-
RUN apk update && \
6-
rm -rf /var/cache/apk/*
7-
8-
COPY ./pom.xml pom.xml
9-
COPY ./src src
10-
11-
RUN cd src/angular/frontend && \
12-
npm install && \
13-
npx ng build --output-path ../../main/resources/static
14-
15-
16-
FROM maven:3.6.3 as backend-build
17-
WORKDIR /classroom-demo
18-
COPY --from=frontend-build /classroom-demo/pom.xml pom.xml
19-
COPY --from=frontend-build /classroom-demo/src/main src/main
20-
21-
RUN mvn clean install
22-
RUN mvn -o package
23-
RUN mv /classroom-demo/target/classroom-demo-*.war /classroom-demo/target/classroom-demo.war
24-
25-
FROM alpine:3.11
1+
FROM alpine:3.17
262

3+
# Install Java and MySQL
274
RUN apk update && \
285
apk add openjdk11-jre && \
296
apk add mysql mysql-client && \
307
rm -rf /var/cache/apk/*
318

9+
# Copy Java application
3210
RUN mkdir -p /opt/classroom-demo
33-
COPY --from=backend-build /classroom-demo/target/classroom-demo.war /opt/classroom-demo/classroom-demo.jar
34-
# Entrypoint
11+
COPY ../target/classroom-demo-*.war /opt/classroom-demo/classroom-demo.jars
12+
13+
# Copy entrypoint
3514
COPY ./docker/entrypoint.sh /usr/local/bin
3615
RUN chmod +x /usr/local/bin/entrypoint.sh
3716

docker/create_image.sh

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
#!/bin/bash
2-
if [ $# -eq 0 ]; then
3-
echo "No version argument provided. Usage: \"./create_image.sh <IMAGE_NAME>\""
4-
exit 1
5-
fi
6-
7-
pushd ../
1+
#!/bin/bash -x
82

9-
docker build -f docker/Dockerfile -t "$1" .
3+
VERSION=$1
4+
if [[ ! -z $VERSION ]]; then
5+
cd ..
6+
docker build --pull --no-cache --rm=true -f docker/Dockerfile -t openvidu/openvidu-classroom-demo:$VERSION .
7+
else
8+
echo "Error: You need to specify a version as first argument"
9+
fi

docker/docker-compose.override.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ services:
88
environment:
99
- SERVER_PORT=5442
1010
- OPENVIDU_URL=http://localhost:5443
11-
- OPENVIDU_SECRET=${OPENVIDU_SECRET}
11+
- OPENVIDU_SECRET=${OPENVIDU_SECRET}

0 commit comments

Comments
 (0)