Skip to content

Commit

Permalink
chore(runtime-exporter): optimize the build process (#1868)
Browse files Browse the repository at this point in the history
Co-authored-by: HUAHUAI23 <[email protected]>
  • Loading branch information
HUAHUAI23 and HUAHUAI23 authored Feb 22, 2024
1 parent f192ec8 commit c023df9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 23 deletions.
13 changes: 13 additions & 0 deletions .github/workflows/dockerize-runtime-exporter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,19 @@ jobs:
ref: ${{ github.event.pull_request.head.ref }}
repository: ${{ github.event.pull_request.head.repo.full_name }}

- name: Use Node
uses: actions/setup-node@v3
with:
node-version: 20.x

- name: Install Package
working-directory: services/runtime-exporter
run: npm cache clean --force && npm install

- name: Build Packages
working-directory: services/runtime-exporter
run: npm run build

- name: Docker meta
id: meta
uses: docker/metadata-action@v4
Expand Down
28 changes: 5 additions & 23 deletions services/runtime-exporter/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,35 +1,17 @@
# Stage 1: Build
FROM node:18-slim AS build

WORKDIR /app

# Utilize cache mechanism, only execute npm install when dependency files change
COPY package*.json ./
RUN npm install

# Copy other files and directories
COPY . .

# Build the application
RUN npm run build

# Stage 2: Set up production environment
FROM node:18-slim AS production
FROM node:20.10.0

# Set environment variables
ENV LOG_LEVEL=debug
ENV NODE_ENV=production

WORKDIR /app

# Copy build artifacts from build stage
COPY --from=build /app/dist ./dist
# Copy production dependencies, omitting development dependencies
COPY --from=build /app/node_modules ./node_modules
COPY --from=build /app/package*.json ./
COPY ./dist /app/dist
COPY ./node_modules /app/node_modules
COPY ./package*.json /app/

# Set non-root user for better security
RUN chown -R node:node /app/
RUN chown -R node:node /app
USER node

# Expose application port
Expand Down

0 comments on commit c023df9

Please sign in to comment.