Skip to content

Commit

Permalink
Merge pull request #2 from terascope/smaller-docker-image
Browse files Browse the repository at this point in the history
Add smaller base docker image without connectors
  • Loading branch information
peterdemartini authored Mar 26, 2021
2 parents 4cba71c + 53046b1 commit ffaea01
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ RUN npm init --yes &> /dev/null \
--build \
--no-package-lock \
--no-optional \
'terafoundation_kafka_connector@~0.5.3' \
'terafoundation_kafka_connector@~0.7.0' \
&& npm cache clean --force

RUN apk del .build-deps
Expand Down
49 changes: 49 additions & 0 deletions Dockerfile.core
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
ARG NODE_VERSION
FROM node:${NODE_VERSION}-alpine

# use an older alpine registry for >=10.19
# because otherwise requiring node-rdkafka breaks
# linux amd64 (like CI)
RUN if [ -z "${NODE_VERSION%%10*}" ]; then \
sed -i -e 's/v3.11/v3.9/g' /etc/apk/repositories \
&& apk upgrade; \
fi

RUN apk --no-cache add \
bash \
curl \
tini \
apk-tools \
build-base \
ca-certificates \
ncurses-terminfo \
libssh2-dev \
openssl-dev \
cyrus-sasl-dev \
python

ENV NPM_CONFIG_LOGLEVEL error
ENV WITH_SASL 0

RUN node --version
RUN yarn --version
RUN npm --version

# Install bunyan
RUN yarn global add \
--ignore-optional \
--no-progress \
--no-emoji \
--no-cache \
bunyan

RUN mkdir -p /app/source
WORKDIR /app/source

COPY docker-pkg-fix.js /usr/local/bin/docker-pkg-fix
COPY wait-for-it.sh /usr/local/bin/wait-for-it

ENV NODE_OPTIONS "--max-old-space-size=2048"

# Use tini to handle sigterm and zombie processes
ENTRYPOINT ["/sbin/tini", "--"]
17 changes: 13 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
# base docker image
# Terascope Base Docker images:

These are the latest docker image tags:
These are the latest docker image tags

- `terascope/node-base:10.23.1`
- `terascope/node-base:12.22.1`
With the terafoundation connectors builtin:

- `terascope/node-base:10.24.0` - 518MB
- `terascope/node-base:12.21.0` - 525MB
- `terascope/node-base:14.16.0` - 553MB

Without: (this will save the image size by roughly 200MB)

- `terascope/node-base:10.24.0-core` - 313MB
- `terascope/node-base:12.21.0-core` - 308MB
- `terascope/node-base:14.16.0-core` - 336MB
20 changes: 16 additions & 4 deletions build-and-push.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ prompt() {
local question="$1"

if [ "$CI" == "true" ]; then
if [ "$TRAVIS_BRANCH" != "master" ] || [ "$TRAVIS_PULL_REQUEST" != "false" ]; then
echo "Skipping until master..."
return 1;
fi
echo "* auto-answer yes to $question since this is running in CI"
return 0
fi
Expand All @@ -28,29 +32,35 @@ prompt() {

docker_build() {
local registry="$1"
local image_type="$3"
local version sub_version

version="$(get_node_version "$2")"
sub_version="$(get_subversion "$2")"

local image_tag="${registry}/node-base:$version$sub_version"
local image_tag="${registry}/node-base:$version$sub_version$image_type"
printf '\n* BUILDING %s...\n\n' "$image_tag"
local file="Dockerfile"
if [ "$image_type" == "-core" ]; then
file="Dockerfile.core"
fi

docker build \
--file "$file" \
--build-arg "NODE_VERSION=$version" \
--no-cache \
--pull \
--tag "$image_tag" .
}

docker_push() {
local registry="$1"
local image_type="$3"
local version sub_version

version="$(get_node_version "$2")"
sub_version="$(get_subversion "$2")"

local image_tag="${registry}/node-base:$version$sub_version"
local image_tag="${registry}/node-base:$version$sub_version$image_type"

printf '\n* PUSHING %s...\n\n' "$image_tag"
docker push "$image_tag"
Expand Down Expand Up @@ -82,9 +92,10 @@ main() {
exit 1
fi

local versions=("10.23.1" "12.20.1")
local versions=("10.24.0" "12.21.0" "14.16.0")
for version in "${versions[@]}"; do
docker_build "$registry" "$version"
docker_build "$registry" "$version" "-core"
done

printf '\n* DONE BUILDING \n\n'
Expand All @@ -93,6 +104,7 @@ main() {

for version in "${versions[@]}"; do
docker_push "$registry" "$version"
docker_push "$registry" "$version" "-core"
done
}

Expand Down

0 comments on commit ffaea01

Please sign in to comment.