Skip to content

Commit e61490d

Browse files
committed
Add health check endpoint and update Dockerfiles for non-root user
1 parent c955025 commit e61490d

6 files changed

Lines changed: 40 additions & 2 deletions

File tree

.github/linters/.trivyignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Ignore the dataplexAdmin role issue
2+
3+
AVD-GCP-0007

.github/linters/.zizmor.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
rules:
2+
unpinned-uses:
3+
ignore: true

.github/workflows/ci.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ jobs:
2424
uses: actions/checkout@v5
2525
with:
2626
fetch-depth: 0
27+
persist-credentials: false
2728

2829
- name: Lint Code Base
2930
uses: super-linter/super-linter/slim@v8.1.0

infra/bigquery-export/Dockerfile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ FROM node:22-slim
44
# Set the working directory
55
WORKDIR /app
66

7+
# Create a non-root user
8+
RUN groupadd -r appuser && useradd -r -g appuser appuser
9+
710
# Copy package files first for better layer caching
811
COPY package*.json ./
912

@@ -15,4 +18,13 @@ ENV EXPORT_CONFIG=""
1518
# Copy source code
1619
COPY . .
1720

21+
# Change ownership of the app directory to the non-root user
22+
RUN chown -R appuser:appuser /app
23+
24+
# Switch to non-root user
25+
USER appuser
26+
27+
# No healthcheck needed for one-time job containers
28+
HEALTHCHECK NONE
29+
1830
CMD ["node", "index.js"]

infra/dataform-service/Dockerfile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ FROM node:22-slim
33
# Set the working directory
44
WORKDIR /app
55

6+
# Create a non-root user
7+
RUN groupadd -r appuser && useradd -r -g appuser appuser
8+
69
# Copy package files first for better layer caching
710
COPY package*.json ./
811

@@ -12,11 +15,21 @@ RUN npm ci --only=production --quiet --no-fund --no-audit && npm cache clean --f
1215
# Copy source code
1316
COPY . .
1417

18+
# Change ownership of the app directory to the non-root user
19+
RUN chown -R appuser:appuser /app
20+
21+
# Switch to non-root user
22+
USER appuser
23+
1524
# Set default port (Cloud Run will override this)
1625
ENV PORT=8080
1726

1827
# Expose port for Cloud Run
1928
EXPOSE 8080
2029

30+
# Add healthcheck
31+
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
32+
CMD node -e "require('http').get('http://localhost:$PORT/health', (res) => { process.exit(res.statusCode === 200 ? 0 : 1) }).on('error', () => { process.exit(1) })" || exit 1
33+
2134
# Start the function
2235
CMD ["npm", "start"]

infra/dataform-service/index.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,14 +223,20 @@ async function mainHandler (req, res) {
223223

224224
console.info(`Received request for path: ${path}`)
225225

226-
if (path === '/trigger' || path.startsWith('/trigger/')) {
226+
if (path === '/health') {
227+
// Health check endpoint
228+
res.status(200).json({
229+
status: 'healthy',
230+
timestamp: new Date().toISOString()
231+
})
232+
} else if (path === '/trigger' || path.startsWith('/trigger/')) {
227233
await handleTrigger(req, res)
228234
} else if (path === '/') {
229235
await handleExport(req, res)
230236
} else {
231237
res.status(404).json({
232238
error: 'Not Found',
233-
message: 'Available endpoints: /, /export'
239+
message: 'Available endpoints: /, /trigger, /health'
234240
})
235241
}
236242
}

0 commit comments

Comments
 (0)