From c55ae94824e1eadc51fed91e0ebb4c60cf4ec0ee Mon Sep 17 00:00:00 2001 From: Vemund Gaukstad Date: Wed, 13 Dec 2023 11:27:32 +0100 Subject: [PATCH] Feature/podman support (#72) * Add separate configs for podman and update the readme to reflect changes made earlier (removal of profiles) * make separate setup section for podman --- .env.template | 2 +- Makefile | 26 +++++----- README.md | 58 +++++++++++++++++++--- docker-compose.yml | 1 + loadbalancer/templates/nginx.conf.conf | 10 ++-- podman-compose.yml | 67 ++++++++++++++++++++++++++ src/appsettings.Podman.json | 8 +++ 7 files changed, 145 insertions(+), 27 deletions(-) create mode 100644 podman-compose.yml create mode 100644 src/appsettings.Podman.json diff --git a/.env.template b/.env.template index 9a085339..f1f7a00b 100644 --- a/.env.template +++ b/.env.template @@ -4,7 +4,7 @@ ## What port should the loadbalancer use? ## sometimes PCs have another service running on port 80, so you might need to -## change this. +## change this. Default in podman-compose.yml is 8080 as ports below 1024 are privileged ports on most unix systems. #ALTINN3LOCAL_PORT=80 diff --git a/Makefile b/Makefile index 387f3f4e..a8628963 100644 --- a/Makefile +++ b/Makefile @@ -1,15 +1,15 @@ -.PHONY: start-localtest -start-localtest: - docker-compose --profile localtest up -d --build +.PHONY: docker-start-localtest +docker-start-localtest: + docker-compose up -d --build -.PHONY: stop-localtest -stop-localtest: - docker-compose --profile localtest down +.PHONY: docker-stop-localtest +docker-stop-localtest: + docker-compose down -.PHONY: start-localtest-new-pdf -start-localtest-new-pdf: - docker-compose --profile localtest --profile pdf up -d --build - -.PHONY: stop-localtest-new-pdf -stop-localtest-new-pdf: - docker-compose --profile localtest --profile pdf down +.PHONY: podman-start-localtest +podman-start-localtest: + podman compose --file podman-compose.yml up -d --build + +.PHONY: podman-stop-localtest +podman-stop-localtest: + podman compose --file podman-compose.yml down \ No newline at end of file diff --git a/README.md b/README.md index 4be14384..d470bb26 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,8 @@ These are some of the required steps, tips, and tricks when it comes to running ### Setup +#### Using docker + 1. Clone the `app-localtest` repository to a local folder and move into the folder. ```shell @@ -28,15 +30,16 @@ These are some of the required steps, tips, and tricks when it comes to running 2. Build and run the containers in the background. ```shell - docker compose --profile localtest up -d --build + docker compose up -d --build ``` - This mode supports running one app at a time. If you need to run multiple apps at once, remove `--profile localtest` from the command and follow the instructions below to run LocalTest locally outside Docker. + :information_source: If you are using linux or mac you can use the Makefile to build and run the containers. - Note: Using profiles requires docker-compose version [1.28.0](https://docs.docker.com/compose/release-notes/#1280) - or later. If your version does not support profiles and you prefer to run localtest in Docker, make sure to follow - [the instructions to install more a recent version](https://docs.docker.com/engine/install/) or comment out - the profile restriction in `docker-compose.yml`. + ```shell + make docker-start-localtest + ``` + + This mode supports running one app at a time. If you need to run multiple apps at once, stop the localtest container with `docker stop localtest` and follow the instructions below to run LocalTest locally outside Docker. 3. Start your app _This step requires that you have already [created an app](https://docs.altinn.studio/app/getting-started/create-app/), added a [data model](https://docs.altinn.studio/app/development/data/data-model/data-models-tool/), and [cloned the app](https://docs.altinn.studio/app/getting-started/local-dev/) to your local environment._ @@ -55,6 +58,46 @@ These are some of the required steps, tips, and tricks when it comes to running dotnet run ``` +#### Using podman + +1. Clone the `app-localtest` repository to a local folder and move into the folder. + + ```shell + git clone https://github.com/Altinn/app-localtest + cd app-localtest + ``` + +2. Build and run the containers in the background. + + ```shell + podman compose --file podman-compose.yml up -d --build + ``` + + :information_source: If you are using linux or mac you can use the Makefile to build and run the containers. + + ```shell + make podman-start-localtest + ``` + + This mode supports running one app at a time. If you need to run multiple apps at once, stop the localtest container with `podman stop localtest` and follow the instructions below to run LocalTest locally outside Docker. + +3. Start your app + _This step requires that you have already [created an app](https://docs.altinn.studio/app/getting-started/create-app/), added a [data model](https://docs.altinn.studio/app/development/data/data-model/data-models-tool/), and [cloned the app](https://docs.altinn.studio/app/getting-started/local-dev/) to your local environment._ + + Move into the `App` folder of your application. + + Example: If your application is named `my-awesome-app` and is located in the folder `C:\my_applications`, run the following command: + + ```shell + cd C:\my_applications\my-awasome-app\App + ``` + + Run the application: + + ```shell + dotnet run + ``` + The app and local platform services are now running locally. The app can be accessed on . Log in with a test user, using your app name and org name. This will redirect you to the app. @@ -90,8 +133,7 @@ The setup described above (LocalTest running in Docker) currently only supports yourself needing to run multiple apps at the same time, or if you need to debug or develop LocalTest, a local setup is preferred. -:information_source: If you're already running LocalTest in Docker, be sure to stop the container or make sure you -omit `--profile localtest` when running `docker compose`. +:information_source: If you're already running LocalTest in Docker, be sure to stop the container with `docker stop localtest` **Configuration of LocalTest** The LocalTest application acts as an emulator of the Altinn 3 platform services. It provides things like authentication, diff --git a/docker-compose.yml b/docker-compose.yml index d12f4924..9f985728 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -17,6 +17,7 @@ services: - NGINX_HOST=localhost - NGINX_PORT=80 - TEST_DOMAIN=${TEST_DOMAIN:-local.altinn.cloud} + - INTERNAL_DOMAIN=host.docker.internal - ALTINN3LOCAL_PORT=${ALTINN3LOCAL_PORT:-80} - NGINX_ENVSUBST_OUTPUT_DIR=/etc/nginx/ - NGINX_ENVSUBST_TEMPLATE_SUFFIX=.conf diff --git a/loadbalancer/templates/nginx.conf.conf b/loadbalancer/templates/nginx.conf.conf index 7e26c95d..e4913d5a 100644 --- a/loadbalancer/templates/nginx.conf.conf +++ b/loadbalancer/templates/nginx.conf.conf @@ -32,11 +32,11 @@ http { sendfile on; upstream localtest { - server host.docker.internal:5101; + server ${INTERNAL_DOMAIN}:5101; } upstream app { - server host.docker.internal:5005; + server ${INTERNAL_DOMAIN}:5005; } # Redirect localhost and the old altinn3local.no to the configured test domain server { @@ -46,15 +46,15 @@ http { } upstream receiptcomp { - server host.docker.internal:5060; + server ${INTERNAL_DOMAIN}:5060; } upstream pdfservice { - server host.docker.internal:5300; + server ${INTERNAL_DOMAIN}:5300; } upstream accessmanagementcomp { - server host.docker.internal:5117; + server ${INTERNAL_DOMAIN}:5117; } server { diff --git a/podman-compose.yml b/podman-compose.yml new file mode 100644 index 00000000..74160d03 --- /dev/null +++ b/podman-compose.yml @@ -0,0 +1,67 @@ +version: '3.6' + +networks: + altinntestlocal_network: + external: false + +services: + local.altinn.cloud: + container_name: localtest-loadbalancer + image: nginx:alpine-perl + restart: always + networks: + - altinntestlocal_network + ports: + - "${ALTINN3LOCAL_PORT:-8080}:80" + environment: + - NGINX_HOST=localhost + - NGINX_PORT=80 + - TEST_DOMAIN=${TEST_DOMAIN:-local.altinn.cloud} + - INTERNAL_DOMAIN=host.containers.internal + - ALTINN3LOCAL_PORT=${ALTINN3LOCAL_PORT:-80} + - NGINX_ENVSUBST_OUTPUT_DIR=/etc/nginx/ + - NGINX_ENVSUBST_TEMPLATE_SUFFIX=.conf + volumes: + - ./loadbalancer/templates:/etc/nginx/templates/:ro + - ./loadbalancer/www:/www/:ro + + + altinn_platform_pdf: + container_name: altinn-pdf + platform: linux/amd64 + image: ghcr.io/altinn/altinn-pdf:latest + restart: always + networks: + - altinntestlocal_network + ports: + - "5070:5070" + altinn_pdf_service: + container_name: altinn-pdf-service + image: browserless/chrome:1-puppeteer-19.2.2 + restart: always + networks: + - altinntestlocal_network + ports: + - "5300:3000" + + altinn_localtest: + container_name: localtest + image: localtest:latest + restart: always + networks: + - altinntestlocal_network + ports: + - "5101:5101" + build: + context: . + environment: + - DOTNET_ENVIRONMENT=Podman + - ASPNETCORE_URLS=http://*:5101/ + - GeneralSettings__BaseUrl=http://${TEST_DOMAIN:-local.altinn.cloud}:${ALTINN3LOCAL_PORT:-80} + - GeneralSettings__HostName=${TEST_DOMAIN:-local.altinn.cloud} + volumes: + - ./testdata:/testdata + - ${ALTINN3LOCALSTORAGE_PATH:-AltinnPlatformLocal}:/AltinnPlatformLocal + +volumes: + AltinnPlatformLocal: diff --git a/src/appsettings.Podman.json b/src/appsettings.Podman.json new file mode 100644 index 00000000..ef53cb54 --- /dev/null +++ b/src/appsettings.Podman.json @@ -0,0 +1,8 @@ +{ + "LocalPlatformSettings": { + "LocalAppMode": "http", + "LocalAppUrl": "http://host.containers.internal:5005", + "LocalTestingStorageBasePath": "/AltinnPlatformLocal/", + "LocalTestingStaticTestDataPath": "/testdata/" + } +}