Skip to content

Commit

Permalink
clean ups
Browse files Browse the repository at this point in the history
  • Loading branch information
framitdavid committed Feb 6, 2024
1 parent d3ec312 commit 310892e
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 21 deletions.
16 changes: 7 additions & 9 deletions development/load-balancer/nginx.conf.conf
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ http {
rewrite /designer/frontend/dashboard/(.*) /$1 break;
proxy_pass http://host.docker.internal:2003;
}

if ($dev_dashboard != 1) {
add_header X-Dashboard-Source dockerDash;
proxy_pass http://studio-designer:6000;
Expand All @@ -71,7 +70,7 @@ http {
if ($dev_app_development) {
add_header X-Dashboard-Source webpackAppDev;
rewrite /designer/frontend/app-development/(.*) /$1 break;
proxy_pass http://host.containers.internal:2004;
proxy_pass http://host.docker.internal:2004;
}
if ($dev_app_development != 1) {
add_header X-Dashboard-Source dockerAppDev;
Expand All @@ -86,7 +85,7 @@ http {
if ($dev_resource_admin) {
add_header X-Dashboard-Source webpackAppDev;
rewrite /designer/frontend/resourceadm/(.*) /$1 break;
proxy_pass http://host.containers.internal:2023;
proxy_pass http://host.docker.internal:2023;
}
if ($dev_resource_admin != 1) {
add_header X-Dashboard-Source dockerAppDev;
Expand All @@ -100,7 +99,7 @@ http {
if ($dev_app_preview) {
add_header X-Dashboard-Source webpackAppDev;
rewrite /designer/frontend/app-preview/(.*) /$1 break;
proxy_pass http://host.containers.internal:2005;
proxy_pass http://host.docker.internal:2005;
}
if ($dev_app_preview != 1) {
add_header X-Dashboard-Source dockerAppDev;
Expand All @@ -114,7 +113,7 @@ http {
if ($dev_studio_root) {
add_header X-Dashboard-Source webpackDash;
rewrite /designer/frontend/studio-root/(.*) /$1 break;
proxy_pass http://host.containers.internal:2002;
proxy_pass http://host.docker.internal:2002;
}
if ($dev_studio_root != 1) {
add_header X-Dashboard-Source dockerDash;
Expand All @@ -129,7 +128,7 @@ http {
proxy_set_header Host $host;
if ($dev_backend) {
add_header X-Dashboard-Source dotnetPaths;
proxy_pass http://host.containers.internal:5000;
proxy_pass http://host.docker.internal:5000;
}
if ($dev_backend != 1) {
add_header X-Dashboard-Source dockerPaths;
Expand All @@ -152,7 +151,7 @@ http {
proxy_set_header Host $host;
if ($dev_backend) {
add_header X-Dashboard-Source dotnetPaths;
proxy_pass http://host.containers.internal:5000;
proxy_pass http://host.docker.internal:5000;
}
if ($dev_backend != 1) {
add_header X-Dashboard-Source dockerPaths;
Expand All @@ -163,7 +162,7 @@ http {
location / {
if ($dev_backend) {
add_header X-Dashboard-Source dotnetRoot;
proxy_pass http://host.containers.internal:5000;
proxy_pass http://host.docker.internal:5000;
}
if ($dev_backend != 1) {
add_header X-Dashboard-Source dockerRoot;
Expand Down Expand Up @@ -238,6 +237,5 @@ http {
location /502Accessmanagement.html {
root /www;
}

}
}
33 changes: 21 additions & 12 deletions development/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,19 @@ class SetupEnvironment extends ContainerTool {

await dnsIsOk(this.host);
if (!(this.env.IGNORE_DOCKER_DNS_LOOKUP === 'true')) {
await dnsIsOk(`host.${this.containerManager}.internal`);
// Podman do also understand host.docker.internal.
await dnsIsOk(`host.docker.internal`);
}

if (this.containerManager === 'podman' && !(await this.isRunningPodmanMachine())) {
await this.createRootfulPodmanMachine();
await this.startPodmanMachine();
} else {
console.log('Podman Machine is already running, continue setup');
}

await this.runCompose();
await waitFor(`http://${this.host}/repos/`);
await this.waitForRepos();
await this.createGiteaAdminUser();
await this.createCypressUser();

Expand All @@ -55,17 +64,17 @@ class SetupEnvironment extends ContainerTool {
}

runCompose() {
if (this.containerManager === 'docker') {
console.log('Using Docker');
runCommand(`docker compose up -d --remove-orphans`);
return;
}
runCommand(
`${this.containerManager} compose --env-file ${path.resolve(__dirname, '../.env')} up -d --remove-orphans`,
);
}

// Podman does not support "--remove-orphans", and doesn't auto-detect .env files, like Docker do. Use "--env-file" to specify .env file.
// Open Issue: https://github.com/containers/podman-compose/issues/815
if (this.containerManager === 'podman') {
runCommand('podman compose down');
runCommand(`podman compose --env-file ${path.resolve(__dirname, '../.env')} up -d`);
async waitForRepos() {
try {
await waitFor(`http://${this.host}/repos/`);
} catch (e) {
console.error(e);
process.exit(1);
}
}

Expand Down
21 changes: 21 additions & 0 deletions development/utils/detect-container-tool.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
const { exec } = require('child_process');

const PODMAN_MACHINE_NAME = 'altinn-studio-rootful-machine';

class ContainerTool {
async detectContainerTool() {
try {
Expand All @@ -20,6 +22,25 @@ class ContainerTool {
exec(command, (error) => (error ? reject(error) : resolve()));
});
}

async isRunningPodmanMachine() {
try {
await this.execCommand(`podman machine inspect ${PODMAN_MACHINE_NAME}`);
return true;
} catch {
return false;
}
}

async createRootfulPodmanMachine() {
console.log('Creating a rootful podman machine');
await this.execCommand(`podman machine init ${PODMAN_MACHINE_NAME} --rootful`);
}

async startPodmanMachine() {
console.log('Starting podman machine');
await this.execCommand(`podman machine start ${PODMAN_MACHINE_NAME}`);
}
}

module.exports = ContainerTool;

0 comments on commit 310892e

Please sign in to comment.