Skip to content

Commit

Permalink
Merge branch 'pratikmallya-simplify_dockerbuild'
Browse files Browse the repository at this point in the history
  • Loading branch information
koalaman committed Mar 21, 2018
2 parents 4861622 + 71bcc80 commit 966194e
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 17 deletions.
23 changes: 11 additions & 12 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,27 @@ before_install:

script:
- mkdir deploy
# Windows .exe
- docker pull koalaman/winghc
- docker run --user="$UID" --rm -v "$PWD:/appdata" koalaman/winghc cuib
- for tag in $TAGS; do cp "dist/build/ShellCheck/shellcheck.exe" "deploy/shellcheck-$tag.exe"; done
- rm -rf dist || true
# Linux static executable
- docker pull koalaman/scbuilder
- docker run --user="$UID" --rm -v "$PWD:/mnt" koalaman/scbuilder
- for tag in $TAGS; do cp "shellcheck" "deploy/shellcheck-$tag.linux"; done
- ./shellcheck --version
- rm -rf dist || true
# Linux Docker image
- name="$DOCKER_BASE"
- DOCKER_BUILDS="$DOCKER_BUILDS $name"
- docker build -t "$name:current" .
- docker run "$name:current" --version
# Copy static executable from docker image
- id=$(docker create "$name:current")
- docker cp "$id:/bin/shellcheck" "shellcheck"
- docker rm "$id"
- for tag in $TAGS; do cp "shellcheck" "deploy/shellcheck-$tag.linux"; done
# Linux Alpine based Docker image
- name="$DOCKER_BASE-alpine"
- DOCKER_BUILDS="$DOCKER_BUILDS $name"
- sed -e 's/^FROM .*/FROM alpine:latest/' -e '/WORKDIR/d' -e '/ENTRYPOINT/d' Dockerfile > Dockerfile.alpine
- sed -e '/DELETE-MARKER/,$d' Dockerfile > Dockerfile.alpine
- docker build -f Dockerfile.alpine -t "$name:current" .
- docker run "$name:current" sh -c 'shellcheck --version'
# Windows .exe
- docker pull koalaman/winghc
- docker run --user="$UID" --rm -v "$PWD:/appdata" koalaman/winghc cuib
- for tag in $TAGS; do cp "dist/build/ShellCheck/shellcheck.exe" "deploy/shellcheck-$tag.exe"; done
- rm -rf dist || true
# Misc packaging
- ./.prepare_deploy

Expand Down
36 changes: 31 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,36 @@
FROM scratch
# Build-only image
FROM ubuntu:17.10 AS build
USER root
WORKDIR /opt/shellCheck

# Install OS deps
RUN apt-get update && apt-get install -y ghc cabal-install

# Install Haskell deps
# (This is a separate copy/run so that source changes don't require rebuilding)
COPY ShellCheck.cabal ./
RUN cabal update && cabal install --dependencies-only

# Copy source and build it
COPY LICENSE Setup.hs shellcheck.hs ./
COPY src src
RUN cabal build Paths_ShellCheck && \
ghc -optl-static -optl-pthread -isrc -idist/build/autogen --make shellcheck && \
strip --strip-all shellcheck

RUN mkdir -p /out/bin && \
cp shellcheck /out/bin/

# Resulting Alpine image
FROM alpine:latest
LABEL maintainer="Vidar Holen <[email protected]>"
COPY --from=build /out /

# This file assumes ShellCheck has already been built.
# See https://github.com/koalaman/scbuilder
COPY shellcheck /bin/shellcheck
# DELETE-MARKER (Remove everything below to keep the alpine image)

WORKDIR /mnt
# Resulting ShellCheck image
FROM scratch
LABEL maintainer="Vidar Holen <[email protected]>"
WORKDIR /
COPY --from=build /out /
ENTRYPOINT ["/bin/shellcheck"]

0 comments on commit 966194e

Please sign in to comment.