Skip to content

Commit 49d11d8

Browse files
authored
Merge pull request #2 from vechain/feat/harden-base-image
Harden base image and add Trivy scan before push
2 parents 9112c0c + d7ac8a4 commit 49d11d8

File tree

2 files changed

+34
-8
lines changed

2 files changed

+34
-8
lines changed

.github/workflows/docker-publish.yml

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,35 @@ jobs:
4040
type=semver,pattern={{major}}.{{minor}}
4141
type=sha
4242
43-
- name: Build and push
43+
- name: Build image
44+
id: build
4445
uses: docker/build-push-action@v5
4546
with:
4647
context: .
47-
push: true
48+
push: false
49+
load: true
4850
tags: ${{ steps.meta.outputs.tags }}
4951
labels: ${{ steps.meta.outputs.labels }}
5052
cache-from: type=gha
5153
cache-to: type=gha,mode=max
54+
55+
- name: Set image ref for Trivy
56+
id: scan-ref
57+
run: |
58+
TAGS="${{ steps.meta.outputs.tags }}"
59+
FIRST_TAG="${TAGS%%$'\n'*}"
60+
echo "ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${FIRST_TAG}" >> $GITHUB_OUTPUT
61+
62+
- name: Run Trivy vulnerability scanner
63+
uses: aquasecurity/trivy-action@master
64+
with:
65+
image-ref: ${{ steps.scan-ref.outputs.ref }}
66+
severity: CRITICAL
67+
exit-code: '1'
68+
format: table
69+
70+
- name: Push image
71+
run: |
72+
echo "${{ steps.meta.outputs.tags }}" | while read t; do
73+
[ -n "$t" ] && docker push "${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:$t"
74+
done

Dockerfile

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
FROM node:20-alpine AS builder
2+
RUN apk add --no-cache tini
23
WORKDIR /app
3-
COPY package.json ./
4-
RUN npm install
4+
COPY package.json package-lock.json ./
5+
RUN npm ci
56
COPY tsconfig.json ./
67
COPY src ./src
78
RUN NODE_OPTIONS=--max-old-space-size=4096 npx tsc
9+
RUN npm prune --production
810

9-
FROM node:20-alpine
10-
RUN apk add --no-cache tini
11+
FROM dhi.io/node:20-alpine3.23
1112
WORKDIR /app
12-
COPY package.json ./
13-
RUN npm install --production
13+
COPY --from=builder /sbin/tini /sbin/tini
1414
COPY --from=builder /app/dist ./dist
15+
COPY --from=builder /app/node_modules ./node_modules
16+
COPY package.json ./
17+
1518
ENV RELAYER_NETWORK=mainnet
1619
ENTRYPOINT ["/sbin/tini", "--"]
1720
CMD ["node", "dist/index.js"]

0 commit comments

Comments
 (0)