Skip to content

Commit

Permalink
Refactor build scripts and Docker image
Browse files Browse the repository at this point in the history
  • Loading branch information
pabloFuente committed Mar 17, 2023
1 parent 40ee76e commit a64f848
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 36 deletions.
47 changes: 47 additions & 0 deletions ci-scripts/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/bin/bash -x
set -eu -o pipefail

#############################################################
# Any function offered by this file assume that the path is #
# located at the root of repository classroom-demo #
#############################################################

# CI flags
BUILD_FRONT=false
BUILD_BACK=false

# Environment variables
if [[ -n ${1:-} ]]; then
case "${1:-}" in
--build-front)
BUILD_FRONT=true
;;
--build-back)
BUILD_BACK=true
;;
*)
echo "Unrecognized method $1"
exit 1
;;
esac
else
echo "Must provide a method to execute as first parameter when calling the script"
exit 1
fi

# -------------
# Build front
# -------------
if [[ "${BUILD_FRONT}" == true ]]; then
rm -rf src/main/resources/static/*
cd src/angular/frontend
npm install --force
npx ng build --output-path ../../../src/main/resources/static
fi

# -------------
# Build back
# -------------
if [[ "${BUILD_BACK}" == true ]]; then
mvn clean compile package
fi
33 changes: 6 additions & 27 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,37 +1,16 @@
FROM node:lts-alpine3.12 as frontend-build

WORKDIR /classroom-demo

RUN apk update && \
rm -rf /var/cache/apk/*

COPY ./pom.xml pom.xml
COPY ./src src

RUN cd src/angular/frontend && \
npm install && \
npx ng build --output-path ../../main/resources/static


FROM maven:3.6.3 as backend-build
WORKDIR /classroom-demo
COPY --from=frontend-build /classroom-demo/pom.xml pom.xml
COPY --from=frontend-build /classroom-demo/src/main src/main

RUN mvn clean install
RUN mvn -o package
RUN mv /classroom-demo/target/classroom-demo-*.war /classroom-demo/target/classroom-demo.war

FROM alpine:3.11
FROM alpine:3.17

# Install Java and MySQL
RUN apk update && \
apk add openjdk11-jre && \
apk add mysql mysql-client && \
rm -rf /var/cache/apk/*

# Copy Java application
RUN mkdir -p /opt/classroom-demo
COPY --from=backend-build /classroom-demo/target/classroom-demo.war /opt/classroom-demo/classroom-demo.jar
# Entrypoint
COPY ../target/classroom-demo-*.war /opt/classroom-demo/classroom-demo.jars

# Copy entrypoint
COPY ./docker/entrypoint.sh /usr/local/bin
RUN chmod +x /usr/local/bin/entrypoint.sh

Expand Down
16 changes: 8 additions & 8 deletions docker/create_image.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/bin/bash
if [ $# -eq 0 ]; then
echo "No version argument provided. Usage: \"./create_image.sh <IMAGE_NAME>\""
exit 1
fi

pushd ../
#!/bin/bash -x

docker build -f docker/Dockerfile -t "$1" .
VERSION=$1
if [[ ! -z $VERSION ]]; then
cd ..
docker build --pull --no-cache --rm=true -f docker/Dockerfile -t openvidu/openvidu-classroom-demo:$VERSION .
else
echo "Error: You need to specify a version as first argument"
fi
2 changes: 1 addition & 1 deletion docker/docker-compose.override.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ services:
environment:
- SERVER_PORT=5442
- OPENVIDU_URL=http://localhost:5443
- OPENVIDU_SECRET=${OPENVIDU_SECRET}
- OPENVIDU_SECRET=${OPENVIDU_SECRET}

0 comments on commit a64f848

Please sign in to comment.