Skip to content

Commit

Permalink
Merge pull request #22 from millenr/A2-2147
Browse files Browse the repository at this point in the history
A2-2147 : Runs UI on /ui for docker container
  • Loading branch information
tsheils authored Dec 1, 2023
2 parents e6465ef + 1eb471e commit 3a83c95
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 15 deletions.
8 changes: 5 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ RUN npm install -g @angular/cli && npm install
COPY . .

# Build the application
RUN ng build --configuration=production
RUN ng build --configuration=production --base-href /ui/

# Stage 2: Setup NGINX
FROM nginx:alpine
Expand All @@ -23,13 +23,15 @@ FROM nginx:alpine
COPY nginx-custom.conf /etc/nginx/conf.d/default.conf

# Copy the build output from Stage 1 to the NGINX html directory
COPY --from=build /app/dist /usr/share/nginx/html
COPY --from=build /app/dist /usr/share/nginx/app
RUN chmod og+r -R /usr/share/nginx/app

# Copy the entrypoint script
COPY ./entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh

# Expose port 4200
# Expose port 80 & 4200
EXPOSE 80
EXPOSE 4200

# Use the entrypoint script
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ To build this container you can either build the docker compose file with `docke

The container can than be run with either `docker compose -f docker-compose.yml up` or `docker run -p 4200:4200 smartgraph-ui`

When running the container the application runs at `http://localhost:4200/ui/`

## Configuring at Runtime

The application reads settings from `/assets/config.json`. While using the docker run option this file can be generated at runtime by setting the following environment variables:
Expand Down
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ services:
environment:
- WRITE_CONFIG=true
- ENVIRONMENT=local
- DATA_URL=ws://localhost:1338/socket.io
- API_SWAGGER_URL=http://localhost:1337/docs/
- DATA_URL=ws://localhost:1338/ws/
- API_SWAGGER_URL=http://localhost:1337/api/docs/
4 changes: 2 additions & 2 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ else
API_SWAGGER_URL="${API_SWAGGER_URL:?Error: API_SWAGGER_URL environment variable not set}"

# Write to config.json file
cat > /usr/share/nginx/html/assets/config.json <<EOF
cat > /usr/share/nginx/app/assets/config.json <<EOF
{
"ENVIRONMENT": "$ENVIRONMENT",
"DATA_URL": "$DATA_URL",
"API_SWAGGER_URL": "$API_SWAGGER_URL"
}
EOF
chmod og+r /usr/share/nginx/html/assets/config.json
chmod og+r /usr/share/nginx/app/assets/config.json
fi

# Start NGINX
Expand Down
8 changes: 4 additions & 4 deletions nginx-custom.conf
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ server {
listen 4200;
server_name localhost;

location / {
root /usr/share/nginx/html;
location /ui/ {
root /usr/share/nginx/app;
index index.html index.htm;
try_files $uri $uri/ /index.html;
try_files $uri $uri/ /ui/index.html;
}

error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
}
13 changes: 10 additions & 3 deletions src/app/services/config.service.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
// src/app/config.service.ts
import { Injectable } from '@angular/core';
import { Inject, Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { DOCUMENT, Location } from '@angular/common';

@Injectable({
providedIn: 'root'
})
export class ConfigService {
private config: any;

constructor(private http: HttpClient) {}
constructor(private http: HttpClient,
@Inject(DOCUMENT) private document: Document,
private location: Location
) {}

loadConfig(): Promise<any> {
return this.http.get('/assets/config.json').toPromise().then((config) => {
const baseUrl = this.document.location.origin + this.location.prepareExternalUrl('/');
const configUrl = `${baseUrl}assets/config.json`;

return this.http.get(configUrl).toPromise().then((config) => {
this.config = config;
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/assets/config.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"ENV": "local",
"DATA_URL": "ws://localhost:1338/socket.io",
"DATA_URL": "ws://localhost:1338/ws",
"API_SWAGGER_URL": "http://localhost:5070/docs"
}

0 comments on commit 3a83c95

Please sign in to comment.