Skip to content
Open
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
48 changes: 29 additions & 19 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,41 +16,51 @@ ARG TARGETOS
ARG TARGETARCH
RUN CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH make build

# Final image
FROM --platform=$TARGETPLATFORM alpine:3.19
# Stage 2: Build TypeScript (if present)
FROM node:16-alpine AS typescript-build

# Install Node.js and npm
RUN apk add --no-cache nodejs npm
# Set working directory
WORKDIR /app

# Copy package files
COPY package*.json ./

# Install dependencies (include TypeScript if necessary)
RUN npm install

# Check if tsconfig.json exists, and if so, install TypeScript and compile
COPY tsconfig.json ./
COPY src/ ./src/
RUN [ -f tsconfig.json ] && npm install -g typescript && tsc || echo "No TypeScript files detected"

# Stage 3: Final runtime image
FROM alpine:3.19

# Install runtime dependencies
RUN apk add --no-cache nodejs npm bash

# Copy binary from builder
COPY --from=builder /app/bin/akavecli /usr/local/bin/akavecli

# Set working directory
WORKDIR /app
# Copy compiled TypeScript (if any) and other files
COPY --from=typescript-build /app/dist ./dist/
COPY --from=typescript-build /app/src ./src/

# Copy package files first (better layer caching)
COPY package*.json ./

# Install only production dependencies
RUN npm install --production

# Copy source files
COPY server.js ./
COPY index.js ./
COPY web3-utils.js ./

# Environment variables with defaults
# Set environment variables
ENV NODE_ADDRESS=""
ENV PRIVATE_KEY=""
ENV PORT=3000
ENV CORS_ORIGIN="*"

# Expose API port
# Expose the API port
EXPOSE 3000

# Health check
# Health check for the service
HEALTHCHECK --interval=30s --timeout=3s \
CMD wget --no-verbose --tries=1 --spider http://localhost:3000/health || exit 1

# Start the API server
CMD ["node", "server.js"]
# Start the server based on available files
CMD ["sh", "-c", "node dist/server.js || node src/server.js"]