wip docker

This commit is contained in:
Simon Prévost 2019-07-18 17:13:24 -04:00
parent c209a6e5d2
commit a9d4511863
7 changed files with 35 additions and 30 deletions

View File

@ -39,12 +39,19 @@ RUN cd /opt/build && \
rm ${APP_NAME}.tar.gz
COPY webapp /opt/build/webapp
RUN cd /opt/build && npm ci --prefix webapp --no-audit --no-color
RUN cd /opt/build && npm run build-production --prefix webapp
COPY jipt /opt/build/jipt
RUN cd /opt/build && \
npm ci --prefix webapp --no-audit --no-color && \
npm ci --prefix jipt --no-audit --no-color
RUN cd /opt/build && npm ci --prefix jipt --no-audit --no-color
RUN cd /opt/build && npm run build-production --prefix jipt
RUN mv /opt/build/webapp/webapp-dist /opt/build
RUN rm -rf /opt/build/webapp
RUN mv /opt/build/jipt/jipt-dist /opt/build
RUN rm -rf /opt/build/jipt
#
# Step 2 - Build a lean runtime container
#
@ -58,21 +65,24 @@ ENV APP_NAME=${APP_NAME} \
# Update kernel and install runtime dependencies
RUN apk --no-cache update && \
apk --no-cache upgrade && \
apk --no-cache add bash openssl erlang-crypto nodejs yaml-dev
apk --no-cache add bash openssl erlang-crypto yaml-dev
WORKDIR /opt/accent
WORKDIR /opt/$APP_NAME
# Copy the OTP binary from the build step
COPY --from=builder /opt/build .
RUN cp -r /opt/$APP_NAME/webapp-dist /opt/$APP_NAME/lib/$APP_NAME-$APP_VERSION/priv/static/webapp
RUN cp -r /opt/$APP_NAME/jipt-dist /opt/$APP_NAME/lib/$APP_NAME-$APP_VERSION/priv/static/jipt
# Copy the entrypoint script
COPY priv/scripts/docker-entrypoint.sh /usr/local/bin
RUN chmod a+x /usr/local/bin/docker-entrypoint.sh
# Create a non-root user
RUN adduser -D accent && chown -R accent: /opt/accent
RUN adduser -D $APP_NAME && chown -R accent: /opt/$APP_NAME
USER accent
USER $APP_NAME
ENTRYPOINT ["docker-entrypoint.sh"]
CMD ["foreground"]

View File

@ -5,7 +5,7 @@
"main": "index.js",
"scripts": {
"build": "parcel index.html",
"build-production": "parcel build index.ts -d ../priv/static/jipt --target browser --experimental-scope-hoisting",
"build-production": "parcel build index.ts --out-dir=jipt-dist --target browser --experimental-scope-hoisting",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],

View File

@ -17,7 +17,7 @@ defmodule Accent.WebAppController do
def index(conn, _) do
conn
|> put_resp_header("content-type", "text/html; charset=utf-8")
|> send_file(:ok, conn.assigns[:file])
|> send_resp(:ok, conn.assigns[:file])
end
def ensure_file_exists(conn, _) do
@ -32,8 +32,13 @@ defmodule Accent.WebAppController do
|> render("maintenance.html")
|> halt()
_ ->
assign(conn, :file, file)
{:ok, content} ->
content = content
|> String.replace("__WEBAPP_AUTH_PROVIDERS__", "dummy")
|> String.replace("__API_HOST__", "http://localhost:4008")
|> String.replace("__API_WS_HOST__", "ws://localhost:4008")
assign(conn, :file, content)
end
end
end

View File

@ -4,15 +4,5 @@ set -e
# Run the migration first using the custom release task
/opt/$APP_NAME/bin/$APP_NAME migrate
# Since an EmberJs app can't be built without its environment, we build it here instead of the Dockerfile.
# This makes the image completly dependent of the deployed instances environment.
cd webapp
./node_modules/ember-cli/bin/ember build --prod --output-path=/opt/$APP_NAME/lib/$APP_NAME-$APP_VERSION/priv/static/webapp &
cd ..
cd jipt
PARCEL_WORKERS=1 ./node_modules/parcel-bundler/bin/cli.js build index.ts --experimental-scope-hoisting --out-dir=/opt/$APP_NAME/lib/$APP_NAME-$APP_VERSION/priv/static/jipt &
cd ..
# Launch the OTP release and replace the caller as Process #1 in the container
exec /opt/$APP_NAME/bin/$APP_NAME "$@"

View File

@ -6,10 +6,10 @@ import config from 'accent-webapp/config/environment';
export default Component.extend({
username: '',
googleLoginEnabled: computed(() => config.AUTH_PROVIDERS.includes('google')),
dummyLoginEnabled: computed(() => config.AUTH_PROVIDERS.includes('dummy')),
githubLoginEnabled: computed(() => config.AUTH_PROVIDERS.includes('github')),
slackLoginEnabled: computed(() => config.AUTH_PROVIDERS.includes('slack')),
googleLoginEnabled: computed(() => config.AUTH_PROVIDERS.split(',').includes('google')),
dummyLoginEnabled: computed(() => config.AUTH_PROVIDERS.split(',').includes('dummy')),
githubLoginEnabled: computed(() => config.AUTH_PROVIDERS.split(',').includes('github')),
slackLoginEnabled: computed(() => config.AUTH_PROVIDERS.split(',').includes('slack')),
googleUrl: computed(() => `${config.API.AUTHENTICATION_PATH}/google`),
githubUrl: computed(() => `${config.API.AUTHENTICATION_PATH}/github`),

View File

@ -4,9 +4,9 @@
// eslint-disable-next-line complexity
module.exports = function(environment) {
const wsHost = process.env.API_WS_HOST || 'ws://localhost:4000';
const host = process.env.API_HOST || 'http://localhost:4000';
const providers = (process.env.WEBAPP_AUTH_PROVIDERS || 'dummy').split(',');
const wsHost = process.env.API_WS_HOST || '__API_WS_HOST__'
const host = process.env.API_HOST || '__API_HOST__'
const providers = process.env.WEBAPP_AUTH_PROVIDERS || '__WEBAPP_AUTH_PROVIDERS__'
const ENV = {
modulePrefix: 'accent-webapp',

View File

@ -14,8 +14,8 @@
},
"scripts": {
"start": "ember server --port $WEBAPP_PORT",
"build": "ember build",
"build-production": "ember build --prod --output-path=../priv/static/webapp",
"build": "ember build --output-path=../priv/static/webapp",
"build-production": "ember build --prod --output-path=webapp-dist",
"test": "ember test"
},
"repository": "https://github.com/mirego/accent",