Skip to content

Commit 368bbfc

Browse files
committed
MOBILE-3738 docker: Bundle assets in image
1 parent 89b3288 commit 368bbfc

File tree

4 files changed

+27
-22
lines changed

4 files changed

+27
-22
lines changed

Dockerfile

+11-21
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,20 @@
1-
# This image is based on the fat node 11 image.
2-
# We require fat images as neither alpine, or slim, include git binaries.
3-
FROM node:11
4-
5-
# Port 8100 for ionic dev server.
6-
EXPOSE 8100
7-
8-
# Port 35729 is the live-reload server.
9-
EXPOSE 35729
10-
11-
# Port 53703 is the Chrome dev logger port.
12-
EXPOSE 53703
1+
## BUILD STAGE
2+
FROM node:14 as build-stage
133

144
WORKDIR /app
155

16-
# Install npm libraries.
6+
# Prepare node dependencies
7+
RUN apt-get update && apt-get install libsecret-1-0 -y
178
COPY package*.json ./
189
RUN npm ci
19-
# Delete caches.
20-
RUN rm -rf /root/.npm
2110

11+
# Build source
12+
ARG build_command="npm run build:prod"
2213
COPY . /app
14+
RUN ${build_command}
2315

24-
# Run gulp before starting.
25-
RUN npx gulp
26-
27-
# Provide a Healthcheck command for easier use in CI.
28-
HEALTHCHECK --interval=10s --timeout=5s --start-period=60s CMD curl -f http://localhost:8100 || exit 1
16+
## SERVE STAGE
17+
FROM nginx:alpine as serve-stage
2918

30-
CMD ["npm", "run", "ionic:serve"]
19+
# Copy assets
20+
COPY --from=build-stage /app/www /usr/share/nginx/html

angular.json

+1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
"builder": "@angular-devkit/build-angular:dev-server",
7070
"options": {
7171
"browserTarget": "app:build",
72+
"disableHostCheck": true,
7273
"port": 8100
7374
},
7475
"configurations": {

hooks/build

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
# Override DockerHub build hook in order to create images of different flavors (production & testing).
3+
# See: https://docs.docker.com/docker-hub/builds/advanced/
4+
5+
if [[ "$IMAGE_NAME" == *-test ]]
6+
then
7+
docker build --build-arg build_command="npm run build:test" -f $DOCKERFILE_PATH -t $IMAGE_NAME .
8+
elif [[ "$IMAGE_NAME" == *-dev ]]
9+
then
10+
docker build --build-arg build_command="npm run build" -f $DOCKERFILE_PATH -t $IMAGE_NAME .
11+
else
12+
docker build -f $DOCKERFILE_PATH -t $IMAGE_NAME .
13+
fi

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
"ng": "ng",
2222
"start": "ionic serve",
2323
"build": "ionic build",
24-
"build:prod": "ionic build --prod",
24+
"build:prod": "NODE_ENV=production ionic build --prod",
25+
"build:test": "NODE_ENV=testing ionic build",
2526
"test": "NODE_ENV=testing gulp && jest --verbose",
2627
"test:ci": "NODE_ENV=testing gulp && jest -ci --runInBand --verbose",
2728
"test:watch": "NODE_ENV=testing gulp watch & jest --watch",

0 commit comments

Comments
 (0)