Skip to content

Commit

Permalink
Fix Docker images for CLI and Docker Image
Browse files Browse the repository at this point in the history
  • Loading branch information
pkosiec committed Sep 30, 2018
1 parent 04110a1 commit 2d4532b
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 17 deletions.
6 changes: 1 addition & 5 deletions cli/.ci/script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,8 @@

IMAGE_NAME="cli-test"

cd ./cli

echo "Building test image..."
docker build -t $IMAGE_NAME:$CI_BUILD_NUMBER .
docker build -t $IMAGE_NAME:$CI_BUILD_NUMBER -f ./cli/Dockerfile .

echo "Running tests with coverage reporting..."
docker run --rm --network="host" $IMAGE_NAME:$CI_BUILD_NUMBER

cd ..
46 changes: 41 additions & 5 deletions cli/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,18 +1,54 @@
# Run with context of the upper level directory

#
# Stage 1
#

FROM node:10-alpine AS builder
LABEL Maintainer="Pawel Kosiec <pawel@kosiec.net>"

ENV CORE_DIR=./core
WORKDIR /app

# Copy sources
COPY $CORE_DIR/package.json $CORE_DIR/package-lock.json $CORE_DIR/tsconfig.json /app/
COPY $CORE_DIR/src /app/src/

# Install dependencies
RUN npm install --no-optional

# Build app
RUN npm run build

# Remove sources
RUN rm -rf /app/src/

#
# Stage 2
#

FROM node:10-alpine

WORKDIR /app

ENV CLI_DIR=./cli

# Install dependencies
COPY package.json package-lock.json /app/
RUN npm i
COPY $CLI_DIR/package.json $CLI_DIR/package-lock.json /app/
RUN npm i --no-optional

# Copy core
COPY --from=builder /app/ /app/node_modules/mongo-seeding/

# Copy app sources
COPY tsconfig.json /app/
COPY src/ /app/src/
COPY test/ /app/test/
COPY $CLI_DIR/tsconfig.json /app/
COPY $CLI_DIR/src/ /app/src/
COPY $CLI_DIR/bin/ /app/bin/
COPY $CLI_DIR/test/ /app/test/

# Build app
RUN npm run build

# Remove built app
RUN npm run cleanup

Expand Down
41 changes: 34 additions & 7 deletions docker-image/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
# Run with context of the upper level directory

#
# Stage 1
# Stage 1: Core
#

FROM node:10-alpine AS builder
FROM node:10-alpine AS coreBuilder
LABEL Maintainer="Pawel Kosiec <pawel@kosiec.net>"

ENV CLI_DIR=./cli
ENV CORE_DIR=./core
WORKDIR /app

# Copy sources
COPY $CLI_DIR/package.json $CLI_DIR/package-lock.json $CLI_DIR/tsconfig.json /app/
COPY $CLI_DIR/bin /app/bin/
COPY $CLI_DIR/src /app/src/
COPY $CORE_DIR/package.json $CORE_DIR/package-lock.json $CORE_DIR/tsconfig.json /app/
COPY $CORE_DIR/src /app/src/

# Install dependencies
RUN npm install --no-optional
Expand All @@ -24,6 +23,34 @@ RUN npm run build
# Remove sources
RUN rm -rf /app/src/

#
# Stage 2: CLI
#

FROM node:10-alpine AS cliBuilder
LABEL Maintainer="Pawel Kosiec <pawel@kosiec.net>"

ENV CLI_DIR=./cli
WORKDIR /app

# Install dependencies
COPY $CLI_DIR/package.json $CLI_DIR/package-lock.json /app/
RUN npm i --no-optional

# Copy core
COPY --from=coreBuilder /app/ /app/node_modules/mongo-seeding/

# Copy app sources
COPY $CLI_DIR/tsconfig.json /app/
COPY $CLI_DIR/src/ /app/src/
COPY $CLI_DIR/bin/ /app/bin/

# Build app
RUN npm run build

# Remove sources
RUN rm -rf /app/src/

#
# Stage 2
#
Expand All @@ -32,7 +59,7 @@ FROM node:10-alpine
WORKDIR /app

# Copy built app
COPY --from=builder /app/ /app/
COPY --from=cliBuilder /app/ /app/

# Create a symlink for "seed" command
RUN npm link
Expand Down

0 comments on commit 2d4532b

Please sign in to comment.