asotog
9/29/2019 - 7:35 PM

static frontend project setuo

  • Dockerfile
FROM twalter/openshift-nginx:mainline-alpine

COPY ./dist /usr/share/nginx/html
COPY docker/nginx.conf /etc/nginx/conf.d/default.conf
COPY docker/entrypoint.sh /

USER root
RUN chmod -R g+rwx /usr/share/nginx/html
USER nginx

CMD ["sh", "/entrypoint.sh"]
  • entrypoint.sh
#!/bin/sh

# Replace env vars in JavaScript files
echo "Replacing env vars in JS"
for file in /usr/share/nginx/html/js/app.*.js;
do
  echo "Processing $file ...";

  # Use the existing JS file as template
  if [ ! -f $file.tmpl.js ]; then
    cp $file $file.tmpl.js
  fi

  envsubst '$BACKEND_HOST $KEYCLOAK_URL $KEYCLOAK_REALM $KEYCLOAK_CLIENT_ID $RENDERER_URL $UNLEASH_URL' < $file.tmpl.js > $file
  rm $file.tmpl.js
done

echo "Starting Nginx"
nginx -g 'daemon off;'
  • docker-compose.yml
version: '3'
services:
  app-web:
    build: .
    ports:
      - 8000:80
    networks:
      - app
    environment:
      BACKEND_HOST: http://localhost:8080
      KEYCLOAK_URL: http://keycloak/auth
      UNLEASH_URL: http://localhost:8080/unleash/api
networks:
  app: