Skip to content

chore(runtime-exporter): Optimize the build process #1868

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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