Skip to content
Open
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
12 changes: 12 additions & 0 deletions .changeset/1844.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
'@asyncapi/cli': minor
---

feat: asyncapi on alpine distros

- de8e46a: feat: asyncapi on alpine distros
- 18f34d2: refactor: added dockerignore and improved Dockerfile
- d0141a8: fix: update dockerfile and lock file and not include lock file in pre commit hooks
- dc87fff: fix: update dockerfile and dockerignore to new github-action dockerfile


90 changes: 87 additions & 3 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,89 @@

# Dependencies
node_modules
npm-debug.log
Dockerfile
.dockerignore
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*

# Build output
lib
dist
*.tgz
*.tar.gz

# Testing
test
coverage
.nyc_output
*.test.*
*.spec.*
__tests__
__mocks__

# Development
.git
.gitignore
.github
.vscode
.idea
*.swp
*.swo
*~

# Documentation
docs
*.md
!README.md
CHANGELOG.md
CONTRIBUTING.md
CODE_OF_CONDUCT.md
DEVELOPMENT.md

# Temporary files and directories
tmp
temp
.tmp
.temp
.cache

# Environment and config files
.env*
.eslintrc*
.prettierrc*
lefthook.yml
nodemon.json
jest.config.*
commitlint.config.js

# OS specific files
.DS_Store
Thumbs.db

# IDE files
*.sublime-project
*.sublime-workspace

# Logs
logs
*.log

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# TypeScript cache
*.tsbuildinfo

# Notes and misc
notes.md
pnpm-lock.yaml

# Action files (for main CLI docker image)
action.yml
action-template.yml

# Test directories and files
test-alpine-fix
89 changes: 34 additions & 55 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,70 +1,49 @@
# Stage 1: Build
FROM node:20-alpine AS build
WORKDIR /app

# Copy the source code
COPY ./ /tmp/source_code

# Install dependencies
RUN cd /tmp/source_code && npm install --ignore-scripts

# Build the source code
RUN cd /tmp/source_code && npm run build

# create libraries directory
RUN mkdir -p /libraries
# Copy package files first for better caching
COPY package*.json ./

# Copy the lib, bin, node_modules, and package.json files to the /libraries directory
RUN cp -r /tmp/source_code/lib /libraries
RUN cp -r /tmp/source_code/assets /libraries
RUN cp /tmp/source_code/package.json /libraries
RUN cp /tmp/source_code/package-lock.json /libraries
RUN cp /tmp/source_code/oclif.manifest.json /libraries
# Install all dependencies (including dev dependencies for build)
RUN npm ci --ignore-scripts

# Copy the bin directory to the /libraries directory
RUN cp -r /tmp/source_code/bin /libraries
# Copy only necessary files for build
COPY src/ ./src/
COPY assets/ ./assets/
COPY scripts/ ./scripts/
COPY bin/ ./bin/
COPY tsconfig.json ./
RUN npm run build && \
npm prune --omit=dev && \
rm -rf test docs .git tmp node_modules/.cache

# Remove everything inside /tmp
RUN rm -rf /tmp/*
# Stage 2: Runtime
FROM ghcr.io/puppeteer/puppeteer:20.8.0

FROM node:20-alpine
# Switch to root to create user and set up permissions
USER root

# Set ARG to explicit value to build chosen version. Default is "latest"
ARG ASYNCAPI_CLI_VERSION=
# Install git
RUN rm -f /etc/apt/sources.list.d/google*.list && \
apt-get update && \
apt-get install -y git && \
rm -rf /var/lib/apt/lists/*

# Create a non-root user
RUN addgroup -S myuser && adduser -S myuser -G myuser
# Create non-root user
RUN groupadd -r asyncapi && useradd -r -g asyncapi asyncapi

# Copy built files from builder stage with correct ownership
WORKDIR /app
COPY --from=build --chown=asyncapi:asyncapi /app /app

# Since 0.14.0 release of html-template chromium is needed for pdf generation
ENV PUPPETEER_EXECUTABLE_PATH /usr/bin/chromium-browser
ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD true
# Since 0.30.0 release Git is supported and required as a dependency
# Since 0.14.0 release of html-template chromium is needed for pdf generation.
# More custom packages for specific template should not be added to this dockerfile. Instead, we should come up with some extensibility solution.
RUN apk --update add git chromium && \
apk add --no-cache --virtual .gyp python3 make g++ && \
rm -rf /var/lib/apt/lists/* && \
rm /var/cache/apk/*

# Copy the libraries directory from the build stage
COPY --from=build /libraries /libraries

# Install the dependencies
RUN cd /libraries && npm install --production --ignore-scripts

# Create a script that runs the desired command
RUN ln -s /libraries/bin/run_bin /usr/local/bin/asyncapi

# Make the script executable
RUN chmod +x /usr/local/bin/asyncapi

# Change ownership to non-root user
RUN chown -R myuser:myuser /libraries /usr/local/bin/asyncapi || echo "Failed to change ownership"
# Create symlink and set permissions
RUN ln -s /app/bin/run_bin /usr/local/bin/asyncapi && \
chmod +x /usr/local/bin/asyncapi

RUN chown -R myuser:myuser /usr/local/lib/node_modules && \
chown -R myuser:myuser /usr/local/bin
# Switch to non-root user for runtime
USER asyncapi

# Switch to the non-root user
USER myuser
ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true

ENTRYPOINT [ "asyncapi" ]
65 changes: 26 additions & 39 deletions github-action/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,52 +1,39 @@
# Stage 1: Build stage with Node setup
FROM node:18-alpine as build
# Stage 1: Build
FROM node:20-alpine AS build
WORKDIR /app

# Copy the source code
COPY ./ /tmp/source_code
# Copy package files first for better caching
COPY package*.json ./

# Install dependencies
RUN cd /tmp/source_code && npm install --ignore-scripts
# Install all dependencies (including dev dependencies for build)
RUN npm ci --ignore-scripts

# Build the source code
RUN cd /tmp/source_code && npm run build
# Copy only necessary files for build
COPY src/ ./src/
COPY assets/ ./assets/
COPY scripts/ ./scripts/
COPY bin/ ./bin/
COPY tsconfig.json ./

# create libraries directory
RUN mkdir -p /libraries
# Build the application
RUN npm run build && \
npm prune --omit=dev && \
rm -rf test docs .git tmp node_modules/.cache

# Copy the lib, bin, node_modules, and package.json files to the /libraries directory
RUN cp -r /tmp/source_code/lib /libraries
RUN cp -r /tmp/source_code/assets /libraries
RUN cp /tmp/source_code/package.json /libraries
RUN cp /tmp/source_code/package-lock.json /libraries
RUN cp /tmp/source_code/oclif.manifest.json /libraries

# Copy the bin directory to the /libraries directory
RUN cp -r /tmp/source_code/bin /libraries

# Remove everything inside /tmp
RUN rm -rf /tmp/*

FROM node:18-alpine
# Stage 2: Runtime
FROM node:20-alpine

# Install necessary packages
RUN apk add --no-cache bash git

# Copy the libraries directory from the build stage
COPY --from=build /libraries /libraries

RUN cd /libraries && npm install --production --ignore-scripts

# Create a non-root user
# RUN addgroup -S myuser && adduser -S myuser -G myuser
RUN apk update && apk add --no-cache bash git && rm -rf /var/cache/apk/*

# Create a script that runs the desired command
RUN ln -s /libraries/bin/run_bin /usr/local/bin/asyncapi
WORKDIR /app

# Make the script executable
RUN chmod +x /usr/local/bin/asyncapi
# Copy built application from build stage
COPY --from=build /app ./

# Change ownership to non-root user
# RUN chown -R myuser:myuser /libraries /usr/local/bin/asyncapi || echo "Failed to change ownership"
# Create symlink for global access
RUN ln -s /app/bin/run_bin /usr/local/bin/asyncapi && \
chmod +x /usr/local/bin/asyncapi

# Copy the entrypoint script
COPY github-action/entrypoint.sh /entrypoint.sh
Expand Down
2 changes: 2 additions & 0 deletions lefthook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ pre-commit:
commands:
lint:
run: npm run lint
exclude: 'package-lock.json'
test:
run: npm run test
exclude: 'package-lock.json'

commit-msg:
parallel: true
Expand Down
Loading
Loading