Skip to content

Commit

Permalink
support any version in Index.cshtml when replacing frontend version (#83
Browse files Browse the repository at this point in the history
)
  • Loading branch information
bjosttveit authored Feb 13, 2024
1 parent 9808173 commit 6609aee
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 11 deletions.
11 changes: 7 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: '3.6'
version: "3.6"

networks:
altinntestlocal_network:
Expand All @@ -7,7 +7,11 @@ networks:
services:
localtest_loadbalancer:
container_name: localtest-loadbalancer
image: nginx:alpine-perl
image: localtest-loadbalancer:latest
build:
context: ./loadbalancer
args:
NGINX_VERSION: 1.25.3
restart: always
networks:
- altinntestlocal_network
Expand All @@ -28,7 +32,6 @@ services:
- ./loadbalancer/templates:/etc/nginx/templates/:ro
- ./loadbalancer/www:/www/:ro


altinn_platform_pdf:
container_name: altinn-pdf
platform: linux/amd64
Expand All @@ -37,7 +40,7 @@ services:
networks:
- altinntestlocal_network
ports:
- "5070:5070"
- "5070:5070"
extra_hosts:
- "host.docker.internal:host-gateway"
altinn_pdf_service:
Expand Down
45 changes: 45 additions & 0 deletions loadbalancer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Based on: https://github.com/tofran/nginx-with-substitutions-filter-docker/blob/main/Dockerfile

ARG NGINX_VERSION

FROM nginx:${NGINX_VERSION}-alpine-perl AS builder

RUN apk add --no-cache --virtual .build-deps \
alpine-sdk \
bash \
findutils \
gcc \
gd-dev \
geoip-dev \
libc-dev \
libedit-dev \
libxslt-dev \
linux-headers \
make \
openssl-dev \
pcre2-dev \
perl-dev \
zlib-dev

RUN mkdir -p /usr/src \
&& wget https://nginx.org/download/nginx-${NGINX_VERSION}.tar.gz -O nginx.tar.gz \
&& wget https://github.com/yaoweibin/ngx_http_substitutions_filter_module/archive/master.tar.gz -O nginx_substitutions_filter.tar.gz \
&& tar -zxC /usr/src -f nginx.tar.gz \
&& tar -zxC /usr/src -f nginx_substitutions_filter.tar.gz \
&& rm nginx.tar.gz \
&& rm nginx_substitutions_filter.tar.gz \
&& cd /usr/src/nginx-$NGINX_VERSION \
&& bash -c 'set -eux && eval ./configure $(nginx -V 2>&1 | sed -n -e "s/^.*configure arguments: //p") --add-dynamic-module=/usr/src/ngx_http_substitutions_filter_module-master' \
&& make \
&& make install

FROM nginx:${NGINX_VERSION}-alpine-perl

COPY --from=builder /usr/lib/nginx/modules/ngx_http_subs_filter_module.so /usr/lib/nginx/modules/ngx_http_subs_filter_module.so

RUN sed -i '1iload_module /usr/lib/nginx/modules/ngx_http_subs_filter_module.so;\n' /etc/nginx/nginx.conf

EXPOSE 80
STOPSIGNAL SIGTERM

CMD ["nginx", "-g", "daemon off;"]
23 changes: 19 additions & 4 deletions loadbalancer/templates/nginx.conf.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
load_module /etc/nginx/modules/ngx_http_perl_module.so;
load_module /usr/lib/nginx/modules/ngx_http_subs_filter_module.so;

worker_processes 1;

Expand All @@ -12,13 +13,25 @@ http {
perl_set $LOCAL_SUB_FILTER 'sub {
my $r = shift;
my $cookie = $r->header_in("cookie");
my $url = $1 if ($cookie =~ /.*frontendVersion=(http.*?);/);
my $url = $1 if ($cookie =~ /.*frontendVersion=(http[^;]+)(;|$)/);
if($url)
{
$uri = $r->unescape($url);
return $uri;
}
return "https://altinncdn.no/toolkits/altinn-app-frontend/3/"
return "";
}';

# If no cookie is set, bypass the sub_filter
perl_set $SUB_FILTER_BYPASS 'sub {
my $r = shift;
my $cookie = $r->header_in("cookie");
my $url = $1 if ($cookie =~ /.*frontendVersion=(http[^;]+)(;|$)/);
if($url)
{
return "0";
}
return "1";
}';

client_max_body_size 50M;
Expand Down Expand Up @@ -75,8 +88,10 @@ http {

location / {
#Support using Local js, when a cookie value is set
sub_filter_once off;
sub_filter 'https://altinncdn.no/toolkits/altinn-app-frontend/3/' $LOCAL_SUB_FILTER;
subs_filter_types text/html;
subs_filter http.+\/(altinn-app-frontend\.(js|css)) $LOCAL_SUB_FILTER$1 gr;
subs_filter_bypass $SUB_FILTER_BYPASS;

proxy_pass http://app/;
error_page 502 /502App.html;
proxy_cookie_domain altinn3local.no local.altinn.cloud;
Expand Down
10 changes: 7 additions & 3 deletions podman-compose.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: '3.6'
version: "3.6"

networks:
altinntestlocal_network:
Expand All @@ -7,7 +7,11 @@ networks:
services:
localtest_loadbalancer:
container_name: localtest-loadbalancer
image: nginx:alpine-perl
image: localtest-loadbalancer:latest
build:
context: ./loadbalancer
args:
NGINX_VERSION: 1.25.3
restart: always
networks:
altinntestlocal_network:
Expand Down Expand Up @@ -36,7 +40,7 @@ services:
networks:
- altinntestlocal_network
ports:
- "5070:5070"
- "5070:5070"

altinn_pdf_service:
container_name: altinn-pdf-service
Expand Down

0 comments on commit 6609aee

Please sign in to comment.