3
0

Updated root Dockerfile and client/web Docker image files

This commit is contained in:
Corteza Monorepo Migrator 2022-11-14 09:26:47 +01:00
parent fb04b735a6
commit 8daaf9488e
4 changed files with 225 additions and 0 deletions

64
Dockerfile Normal file
View File

@ -0,0 +1,64 @@
# build-stage
FROM alpine:3 as build-stage
# use docker build --build-arg VERSION=2021.9.0 .
ARG VERSION=2022.9.0
ARG SERVER_VERSION=${VERSION}
ARG WEBAPP_VERSION=${VERSION}
ARG CORTEZA_SERVER_PATH=https://releases.cortezaproject.org/files/corteza-server-${SERVER_VERSION}-linux-amd64.tar.gz
ARG CORTEZA_WEBAPP_PATH=https://releases.cortezaproject.org/files/corteza-webapp-${WEBAPP_VERSION}.tar.gz
RUN mkdir /tmp/server
RUN mkdir /tmp/webapp
ADD $CORTEZA_SERVER_PATH /tmp/server
ADD $CORTEZA_WEBAPP_PATH /tmp/webapp
RUN apk update && apk add --no-cache file
RUN file "/tmp/server/$(basename $CORTEZA_SERVER_PATH)" | grep -q 'gzip' && \
tar zxvf "/tmp/server/$(basename $CORTEZA_SERVER_PATH)" -C / || \
cp -a "/tmp/server" /
RUN mv /corteza-server /corteza
WORKDIR /corteza
RUN rm -rf /corteza/webapp
RUN file "/tmp/webapp/$(basename $CORTEZA_WEBAPP_PATH)" | grep -q 'gzip' && \
mkdir /corteza/webapp && tar zxvf "/tmp/webapp/$(basename $CORTEZA_WEBAPP_PATH)" -C /corteza/webapp || \
cp -a "/tmp/webapp" /corteza/webapp
# deploy-stage
FROM ubuntu:20.04
RUN apt-get -y update \
&& apt-get -y install \
ca-certificates \
curl \
&& rm -rf /var/lib/apt/lists/*
ENV STORAGE_PATH "/data"
ENV CORREDOR_ADDR "corredor:80"
ENV HTTP_ADDR "0.0.0.0:80"
ENV HTTP_WEBAPP_ENABLED "true"
ENV HTTP_WEBAPP_BASE_DIR "/corteza/webapp"
ENV PATH "/corteza/bin:${PATH}"
WORKDIR /corteza
VOLUME /data
COPY --from=build-stage /corteza ./
HEALTHCHECK --interval=30s --start-period=1m --timeout=30s --retries=3 \
CMD curl --silent --fail --fail-early http://127.0.0.1:80/healthcheck || exit 1
EXPOSE 80
ENTRYPOINT ["./bin/corteza-server"]
CMD ["serve-api"]

36
client/web/Dockerfile Normal file
View File

@ -0,0 +1,36 @@
# build-stage
FROM alpine:3 as build-stage
ARG VERSION=2022.9.0
ARG CORTEZA_CLIENT_WEB_AIO_PKG=https://releases.cortezaproject.org/files/corteza-webapp-${VERSION}.tar.gz
# Download package
ADD $CORTEZA_CLIENT_WEB_AIO_PKG /tmp
RUN apk update && apk add --no-cache file
RUN rm -rf /html; mkdir /html
WORKDIR /html
RUN file "/tmp/$(basename $CORTEZA_CLIENT_WEB_AIO_PKG)" | grep -q 'gzip' && \
tar zxvf "/tmp/$(basename $CORTEZA_CLIENT_WEB_AIO_PKG)" -C /html
# deploy-stage
FROM nginx:stable-alpine
WORKDIR /usr/share/nginx/html
COPY --from=build-stage /html /usr/share/nginx/html
COPY nginx.conf /etc/nginx/nginx.conf
#COPY CONTRIBUTING.* DCO LICENSE README.* ./
COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
EXPOSE 80
HEALTHCHECK --interval=30s --start-period=10s --timeout=30s \
CMD wget --quiet --tries=1 --spider "http://127.0.0.1:80/config.js" || exit 1
ENTRYPOINT ["/entrypoint.sh"]

55
client/web/entrypoint.sh Normal file
View File

@ -0,0 +1,55 @@
#!/bin/sh
set -eu
if [ ! -z "${1:-}" ]; then
exec "$@"
else
function config() {
prefix=$1
# check if config.js is present (via volume)
# or if it's missing
if [ ! -f "$prefix/config.js" ]; then
# config.js missing, generate it
if [ ! -z "${CONFIGJS:-}" ]; then
# use $CONFIGJS variable that might be passed to the container:
# --env CONFIGJS="$(cat public/config.example.js)"
echo "${CONFIGJS}" > "$prefix/config.js"
else
# Try to guess where the API is located by using DOMAIN or VIRTUAL_HOST and prefix it with "api."
API_HOST=${API_HOST:-"api.${VIRTUAL_HOST:-"${DOMAIN:-"local.cortezaproject.org"}"}"}
API_BASEURL=${API_FULL_URL:-"//${API_HOST}"}
DISCOVERY_BASEURL=${DISCOVERY_BASE_URL:-"//discovery.local.cortezaproject.org"}
echo "window.CortezaAPI = '${API_BASEURL}'" > "$prefix/config.js"
echo "window.CortezaDiscoveryAPI = '${DISCOVERY_BASEURL}'" >> "$prefix/config.js"
fi
fi
BASE_PATH=${BASE_PATH:-"/"}
if [ $BASE_PATH != "/" ]; then
BASE_PATH_LENGTH=${#BASE_PATH}
BASE_PATH_LAST_CHAR=${BASE_PATH:BASE_PATH_LENGTH-1:1}
if [ $BASE_PATH_LAST_CHAR != "/" ]; then
BASE_PATH="$BASE_PATH/"
fi
fi
sed -i "s|<base href=/ >|<base href=\"${BASE_PATH}$(echo "$prefix/" | cut -c 3-)\">|g" "$prefix/index.html"
sed -i "s|<base href=\"/\">|<base href=\"${BASE_PATH}$(echo "$prefix/" | cut -c 3-)\">|g" "$prefix/index.html"
sed -i "s|{{BASE_PATH}}|$BASE_PATH|g" /etc/nginx/nginx.conf
}
config './admin'
config './reporter'
config './compose'
config './workflow'
config './discovery'
config './privacy'
config '.'
nginx -g "daemon off;"
fi

70
client/web/nginx.conf Normal file
View File

@ -0,0 +1,70 @@
user nginx;
worker_processes 1;
error_log /dev/stdout warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format json escape=json
'{'
'"@timestamp":"$time_iso8601",'
'"remote_addr":"$remote_addr",'
'"request":"$request",'
'"status":$status,'
'"body_bytes_sent":$body_bytes_sent,'
'"request_time":$request_time,'
'"http_referrer":"$http_referer",'
'"http_user_agent":"$http_user_agent"'
'}';
access_log /dev/stdout json;
sendfile on;
keepalive_timeout 300;
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
index index.html;
root /usr/share/nginx/html;
location {{BASE_PATH}}admin {
try_files $uri {{BASE_PATH}}admin/index.html;
}
location {{BASE_PATH}}compose {
try_files $uri {{BASE_PATH}}compose/index.html;
}
location {{BASE_PATH}}workflow {
try_files $uri {{BASE_PATH}}workflow/index.html;
}
location {{BASE_PATH}}reporter {
try_files $uri {{BASE_PATH}}reporter/index.html;
}
location {{BASE_PATH}}discovery {
try_files $uri {{BASE_PATH}}discovery/index.html;
}
location {{BASE_PATH}}privacy {
try_files $uri {{BASE_PATH}}privacy/index.html;
}
location {{BASE_PATH}} {
try_files $uri {{BASE_PATH}}index.html;
}
}
}