commit
b4368d8aa6
35
Dockerfile
35
Dockerfile
|
@ -1,27 +1,20 @@
|
||||||
# This image is based on the fat node 14 image.
|
## BUILD STAGE
|
||||||
# We require fat images as neither alpine, or slim, include git binaries.
|
FROM node:14 as build-stage
|
||||||
FROM node:14
|
|
||||||
|
|
||||||
# Port 8100 for ionic dev server.
|
|
||||||
EXPOSE 8100
|
|
||||||
|
|
||||||
# Port 35729 is the live-reload server.
|
|
||||||
EXPOSE 35729
|
|
||||||
|
|
||||||
# Port 53703 is the Chrome dev logger port.
|
|
||||||
EXPOSE 53703
|
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
|
# Prepare node dependencies
|
||||||
|
RUN apt-get update && apt-get install libsecret-1-0 -y
|
||||||
|
COPY package*.json ./
|
||||||
|
RUN npm ci
|
||||||
|
|
||||||
|
# Build source
|
||||||
|
ARG build_command="npm run build:prod"
|
||||||
COPY . /app
|
COPY . /app
|
||||||
|
RUN ${build_command}
|
||||||
|
|
||||||
# Install npm libraries.
|
## SERVE STAGE
|
||||||
RUN npm install && rm -rf /root/.npm
|
FROM nginx:alpine as serve-stage
|
||||||
|
|
||||||
# Run gulp before starting.
|
# Copy assets
|
||||||
RUN npx gulp
|
COPY --from=build-stage /app/www /usr/share/nginx/html
|
||||||
|
|
||||||
# Provide a Healthcheck command for easier use in CI.
|
|
||||||
HEALTHCHECK --interval=10s --timeout=5s --start-period=60s CMD curl -f http://localhost:8100 || exit 1
|
|
||||||
|
|
||||||
CMD ["npm", "run", "ionic:serve"]
|
|
||||||
|
|
|
@ -69,6 +69,7 @@
|
||||||
"builder": "@angular-devkit/build-angular:dev-server",
|
"builder": "@angular-devkit/build-angular:dev-server",
|
||||||
"options": {
|
"options": {
|
||||||
"browserTarget": "app:build",
|
"browserTarget": "app:build",
|
||||||
|
"disableHostCheck": true,
|
||||||
"port": 8100
|
"port": 8100
|
||||||
},
|
},
|
||||||
"configurations": {
|
"configurations": {
|
||||||
|
|
|
@ -12,9 +12,44 @@
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
const { getConfig, getBuild } = require('../scripts/env-utils');
|
const { execSync } = require('child_process');
|
||||||
|
const { existsSync, readFileSync, writeFile } = require('fs');
|
||||||
|
const { parse: parseJsonc } = require('jsonc-parser');
|
||||||
const { resolve } = require('path');
|
const { resolve } = require('path');
|
||||||
const { writeFile } = require('fs');
|
|
||||||
|
function getConfig(environment) {
|
||||||
|
const envSuffixesMap = {
|
||||||
|
testing: ['test', 'testing'],
|
||||||
|
development: ['dev', 'development'],
|
||||||
|
production: ['prod', 'production'],
|
||||||
|
};
|
||||||
|
const config = parseJsonc(readFileSync(resolve(__dirname, '../moodle.config.json')).toString());
|
||||||
|
const envSuffixes = (envSuffixesMap[environment] || []);
|
||||||
|
const envConfigPath = envSuffixes.map(suffix => resolve(__dirname, `../moodle.${suffix}.config.json`)).find(existsSync);
|
||||||
|
|
||||||
|
if (envConfigPath) {
|
||||||
|
const envConfig = parseJsonc(readFileSync(envConfigPath).toString());
|
||||||
|
|
||||||
|
for (const [key, value] of Object.entries(envConfig)) {
|
||||||
|
config[key] = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return config;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getBuild(environment) {
|
||||||
|
const { version } = JSON.parse(readFileSync(resolve(__dirname, '../package.json')));
|
||||||
|
|
||||||
|
return {
|
||||||
|
version,
|
||||||
|
isProduction: environment === 'production',
|
||||||
|
isTesting: environment === 'testing',
|
||||||
|
isDevelopment: environment === 'development',
|
||||||
|
lastCommitHash: execSync('git log -1 --pretty=format:"%H"').toString(),
|
||||||
|
compilationTime: Date.now(),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Task to build an env file depending on the current environment.
|
* Task to build an env file depending on the current environment.
|
||||||
|
@ -29,8 +64,8 @@ class BuildEnvTask {
|
||||||
run(done) {
|
run(done) {
|
||||||
const envFile = resolve(__dirname, '../src/assets/env.json');
|
const envFile = resolve(__dirname, '../src/assets/env.json');
|
||||||
const env = {
|
const env = {
|
||||||
CONFIG: getConfig(process.env.NODE_ENV || 'development'),
|
config: getConfig(process.env.NODE_ENV || 'development'),
|
||||||
BUILD: getBuild(process.env.NODE_ENV || 'development'),
|
build: getBuild(process.env.NODE_ENV || 'development'),
|
||||||
};
|
};
|
||||||
|
|
||||||
writeFile(envFile, JSON.stringify(env), done);
|
writeFile(envFile, JSON.stringify(env), done);
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
#!/bin/bash
|
||||||
|
# Override DockerHub build hook in order to create images of different flavors (production & testing).
|
||||||
|
# See: https://docs.docker.com/docker-hub/builds/advanced/
|
||||||
|
|
||||||
|
if [[ "$IMAGE_NAME" == *-test ]]
|
||||||
|
then
|
||||||
|
docker build --build-arg build_command="npm run build:test" -f $DOCKERFILE_PATH -t $IMAGE_NAME .
|
||||||
|
elif [[ "$IMAGE_NAME" == *-dev ]]
|
||||||
|
then
|
||||||
|
docker build --build-arg build_command="npm run build" -f $DOCKERFILE_PATH -t $IMAGE_NAME .
|
||||||
|
else
|
||||||
|
docker build -f $DOCKERFILE_PATH -t $IMAGE_NAME .
|
||||||
|
fi
|
|
@ -21,7 +21,8 @@
|
||||||
"ng": "ng",
|
"ng": "ng",
|
||||||
"start": "ionic serve",
|
"start": "ionic serve",
|
||||||
"build": "ionic build",
|
"build": "ionic build",
|
||||||
"build:prod": "ionic build --prod",
|
"build:prod": "NODE_ENV=production ionic build --prod",
|
||||||
|
"build:test": "NODE_ENV=testing ionic build",
|
||||||
"test": "NODE_ENV=testing gulp && jest --verbose",
|
"test": "NODE_ENV=testing gulp && jest --verbose",
|
||||||
"test:ci": "NODE_ENV=testing gulp && jest -ci --runInBand --verbose",
|
"test:ci": "NODE_ENV=testing gulp && jest -ci --runInBand --verbose",
|
||||||
"test:watch": "NODE_ENV=testing gulp watch & jest --watch",
|
"test:watch": "NODE_ENV=testing gulp watch & jest --watch",
|
||||||
|
|
|
@ -1,51 +0,0 @@
|
||||||
// (C) Copyright 2015 Moodle Pty Ltd.
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
const { execSync } = require('child_process');
|
|
||||||
const { resolve } = require('path');
|
|
||||||
|
|
||||||
function getConfig(environment) {
|
|
||||||
const { parse: parseJsonc } = require('jsonc-parser');
|
|
||||||
const { readFileSync, existsSync } = require('fs');
|
|
||||||
const envSuffixesMap = {
|
|
||||||
testing: ['test', 'testing'],
|
|
||||||
development: ['dev', 'development'],
|
|
||||||
production: ['prod', 'production'],
|
|
||||||
};
|
|
||||||
const config = parseJsonc(readFileSync(resolve(__dirname, '../moodle.config.json')).toString());
|
|
||||||
const envSuffixes = (envSuffixesMap[environment] || []);
|
|
||||||
const envConfigPath = envSuffixes.map(suffix => resolve(__dirname, `../moodle.${suffix}.config.json`)).find(existsSync);
|
|
||||||
|
|
||||||
if (envConfigPath) {
|
|
||||||
const envConfig = parseJsonc(readFileSync(envConfigPath).toString());
|
|
||||||
|
|
||||||
for (const [key, value] of Object.entries(envConfig)) {
|
|
||||||
config[key] = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return config;
|
|
||||||
}
|
|
||||||
|
|
||||||
function getBuild(environment) {
|
|
||||||
return {
|
|
||||||
isProduction: environment === 'production',
|
|
||||||
isTesting: environment === 'testing',
|
|
||||||
isDevelopment: environment === 'development',
|
|
||||||
lastCommitHash: execSync('git log -1 --pretty=format:"%H"').toString(),
|
|
||||||
compilationTime: Date.now(),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = { getConfig, getBuild };
|
|
|
@ -126,8 +126,8 @@ export class CoreConstants {
|
||||||
static readonly MOD_ARCHETYPE_SYSTEM = 3; // System (not user-addable) module archetype.
|
static readonly MOD_ARCHETYPE_SYSTEM = 3; // System (not user-addable) module archetype.
|
||||||
|
|
||||||
// Config & environment constants.
|
// Config & environment constants.
|
||||||
static readonly CONFIG = envJson.CONFIG as unknown as EnvironmentConfig; // Data parsed from config.json files.
|
static readonly CONFIG = envJson.config as unknown as EnvironmentConfig; // Data parsed from config.json files.
|
||||||
static readonly BUILD = envJson.BUILD as unknown as EnvironmentBuild; // Build info.
|
static readonly BUILD = envJson.build as unknown as EnvironmentBuild; // Build info.
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -168,6 +168,7 @@ type EnvironmentConfig = {
|
||||||
};
|
};
|
||||||
|
|
||||||
type EnvironmentBuild = {
|
type EnvironmentBuild = {
|
||||||
|
version: string;
|
||||||
isProduction: boolean;
|
isProduction: boolean;
|
||||||
isTesting: boolean;
|
isTesting: boolean;
|
||||||
isDevelopment: boolean;
|
isDevelopment: boolean;
|
||||||
|
|
Loading…
Reference in New Issue