Skip to content

Commit c2ab334

Browse files
authored
ci(docker): Make AHBesser Prod and Stage ready (#356)
* add pulumi prod config * add pulumi prod config * sort pulumi configs * add shell script for start up * add more files and folders to .dockerignore * pulumi add environment to env vars * set environment variable environment * wip start.sh * use single stage dockerfile * improve start.sh * use non-root user * sort pulumi files
1 parent 82662d6 commit c2ab334

File tree

6 files changed

+69
-22
lines changed

6 files changed

+69
-22
lines changed

.dockerignore

+11
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,14 @@ node_modules
1515
.prettierrc
1616
README.md
1717
*.tsbuildinfo
18+
19+
20+
.DS_Store
21+
.env
22+
.example.env
23+
.github
24+
.gitmodules
25+
.idea
26+
.octopus
27+
azure-mock
28+
node_modules

Dockerfile

+19-21
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,36 @@
1-
# BUILDER IMAGE
2-
FROM node:23.5-alpine AS builder
3-
4-
WORKDIR /service
5-
6-
COPY . .
7-
8-
RUN npm ci --no-scripts
9-
10-
RUN npm run ng:build
11-
RUN npm run server:build
12-
13-
# PRODUCTION IMAGE
1+
# Single-Stage Dockerfile
142
FROM node:23.5-alpine
153

16-
# Set build arguments
4+
# Set environment arguments and variables
175
ARG BUILD_DATE
186
ARG COMMIT_ID
197
ARG VERSION
208

21-
# Set environment variables
22-
ENV BUILD_DATE=$BUILD_DATE
23-
ENV COMMIT_ID=$COMMIT_ID
24-
ENV VERSION=$VERSION
9+
# Environment variables
10+
ENV BUILD_DATE=$BUILD_DATE \
11+
COMMIT_ID=$COMMIT_ID \
12+
VERSION=$VERSION
2513

2614
WORKDIR /service
2715

16+
# Create a non-root user for security
2817
RUN addgroup --system --gid 1001 nodejs && \
2918
adduser --system --uid 1001 nodejs
3019

31-
COPY --chown=nodejs:nodejs --from=builder /service/dist dist
32-
COPY --chown=nodejs:nodejs --from=builder /service/node_modules node_modules
20+
# Copy all necessary files into the image
21+
COPY . .
22+
23+
# Change ownership of the service folder and all copied files to the nodejs user
24+
RUN chown -R nodejs:nodejs /service
25+
26+
# Install dependencies
27+
RUN npm ci --no-scripts
3328

29+
# Switch to non-root user
3430
USER nodejs
3531

32+
# Expose port for the server
3633
EXPOSE 3000
3734

38-
CMD node dist/server/server.js
35+
# Start the application via start.sh script
36+
CMD ["sh", "./start.sh"]

pulumi/Pulumi.dev.yaml

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
config:
22
ahb-tabellen:ahbBlobContainerName: ahb-tables
33
ahb-tabellen:appPath: app
4+
ahb-tabellen:bedingungsbaumBaseUrl: https://bedingungsbaum.stage.hochfrequenz.de
45
ahb-tabellen:containerPort: "80"
56
ahb-tabellen:cpu: "1"
7+
ahb-tabellen:environment: stage
68
ahb-tabellen:formatVersionContainerName: format-versions
79
ahb-tabellen:ghcr_token:
810
secure: AAABAEg7fEk2P91sxA8mlsQ5AueGPcKpU5H8jCLGvH82HsWD1NkdQLT69wDwMfdI7Nc+jSdwJC4Wx/ym4m3HUMGxgeK9RJt0
911
ahb-tabellen:imageName: ghcr.io/hochfrequenz/ahbesser
1012
ahb-tabellen:imageTag: v0.0.22
1113
ahb-tabellen:memory: "2"
12-
ahb-tabellen:bedingungsbaumBaseUrl: https://bedingungsbaum.stage.hochfrequenz.de
1314
azure-native:location: germanywestcentral
1415
pulumi:template: container-azure-python

pulumi/Pulumi.prod.yaml

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
config:
2+
ahb-tabellen:ahbBlobContainerName: ahb-tables
3+
ahb-tabellen:appPath: app
4+
ahb-tabellen:bedingungsbaumBaseUrl: https://bedingungsbaum.hochfrequenz.de
5+
ahb-tabellen:containerPort: "80"
6+
ahb-tabellen:cpu: "1"
7+
ahb-tabellen:environment: production
8+
ahb-tabellen:formatVersionContainerName: format-versions
9+
ahb-tabellen:ghcr_token:
10+
secure: AAABAKDpxgOPRYBk2KIdX7mlihB3y/nJDFZQsK2/2Mf88W8XnEeC4JbZSsDwPfvq0vZjnHa/x3iU6Kt2V1ww8jO3YiXKAswf
11+
ahb-tabellen:imageName: ghcr.io/hochfrequenz/ahbesser
12+
ahb-tabellen:imageTag: v0.0.22
13+
ahb-tabellen:location: germanywestcentral
14+
ahb-tabellen:memory: "2"
15+
azure-native:location: germanywestcentral
16+
pulumi:template: container-azure-python

pulumi/__main__.py

+4
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@
2929
bedingungsbaum_base_url = config.get("bedingungsbaumBaseUrl")
3030
assert bedingungsbaum_base_url, "bedingungsbaumBaseUrl must be set"
3131

32+
environment = config.get("environment")
33+
assert environment, "environment must be set"
34+
3235
cpu = config.get_int("cpu", 1)
3336
memory = config.get_int("memory", 2)
3437

@@ -112,6 +115,7 @@
112115
azure_native.web.NameValuePairArgs(
113116
name="BEDINGUNGSBAUM_BASE_URL", value=bedingungsbaum_base_url
114117
),
118+
azure_native.web.NameValuePairArgs(name="ENVIRONMENT", value=environment),
115119
],
116120
linux_fx_version=f"DOCKER|{image_name_with_tag}",
117121
),

start.sh

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/sh
2+
3+
# Exit immediately if a command exits with a non-zero status
4+
set -e
5+
6+
echo "Starting application setup with environment: $ENVIRONMENT"
7+
8+
# Build the Angular application using local Angular CLI
9+
echo "Building Angular application..."
10+
npm run ng:build --configuration=$ENVIRONMENT
11+
12+
# Build the Express server
13+
echo "Building Express server..."
14+
npm run server:build
15+
16+
# Start the server
17+
node dist/server/server.js

0 commit comments

Comments
 (0)