Skip to content

Commit

Permalink
Create Linux release version with Docker.
Browse files Browse the repository at this point in the history
  • Loading branch information
acook committed Feb 14, 2021
1 parent a469198 commit 1c9ded3
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 0 deletions.
22 changes: 22 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
FROM crystallang/crystal:0.36.1-alpine
WORKDIR /app
COPY . .

# dependencies
RUN apk add libmagic

# work around alpine not shipping with static libmagic.a
RUN apk add libtool autoconf automake
RUN mkdir -p /opt/src
# zlib
RUN cd /opt/src && git clone https://github.com/madler/zlib.git && cd zlib && ./configure --static --64 && make
# bz2
RUN cd /opt/src && git clone git://sourceware.org/git/bzip2.git && cd bzip2 && make
# file/libmagic
RUN cd /opt/src && git clone https://github.com/file/file.git
RUN cd /opt/src/file && SH_LIBTOOL='/usr/share/build-1/libtool' autoreconf -f -i
RUN cd /opt/src/file && CFLAGS="-static" ./configure --prefix=/usr --datadir=/usr/share --enable-static --disable-xzlib
RUN cd /opt/src/file && make LDFLAGS="-all-static"

# by default just run the tests
CMD ["crystal", "spec"]
3 changes: 3 additions & 0 deletions scripts/console_docker
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash

docker run -it --entrypoint /bin/sh -v "$PWD":/workspace -w /workspace lister:latest
41 changes: 41 additions & 0 deletions scripts/release
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/usr/bin/env bash

thispath="$(dirname "${BASH_SOURCE[0]}")"

cd "$thispath"/.. || exit 1

command_exists() { command -v "$1" > /dev/null 2>&1; }
#find_libd () { dirname "$(find /usr/lib /opt /usr/local/opt -name "*lib$1.so*" -quit 2> /dev/null;)"; }
find_liba () { find /usr/lib /opt /usr/local/opt -name "*lib$1.a*" -quit 2> /dev/null; }

if command_exists osinfo.bash; then
OS=$(osinfo.bash)
else
OS=$(uname)
fi

# Linker flags, primarily useful for static builds but also for systems which don't have libraries in the normal search path
if command_exists brew; then
# MacOS Linker flags from Homebrew
echo "Pulling library dependencies from Homebrew..."
LINK_FLAGS="$(brew --prefix zlib)/lib/libz.a $(brew --prefix bzip2)/lib/libbz2.a $(brew --prefix libmagic)/lib/libmagic.a"
else
# ideally these should be pulled in for any OS
echo "Looking for libraries, this might take some time, especially if they're missing!"
LINK_FLAGS="-lmagic -lz -lbz2 $(find_liba magic) $(find_liba z) $(find_liba bz2)"
fi

echo "Building standard release for native platform ($OS)..."
crystal build src/lister.cr -o "bin/lister.$OS" --release --no-debug
echo "Building libmagic-static release for native platform ($OS)..."
crystal build src/lister.cr -o "bin/lister.static.$OS" --release --no-debug --link-flags "$LINK_FLAGS"

# for the docker image with known locations
ALPINE_LINK_FLAGS="-lmagic -lz -lbz2 -L /opt/src/file/src/.libs -L /opt/src/zlib -L /opt/src/bzip2"

echo "Building standard release for Linux x86_64..."
docker run --rm -it -v "$PWD":/workspace -w /workspace lister:latest \
crystal build src/lister.cr -o "bin/lister.alpine" --release --no-debug --link-flags "$ALPINE_LINK_FLAGS"
echo "Building static release for Linux x86_64..."
docker run --rm -it -v "$PWD":/workspace -w /workspace lister:latest \
crystal build src/lister.cr -o "bin/lister.static.alpine" --static --release --no-debug --link-flags "$ALPINE_LINK_FLAGS"

0 comments on commit 1c9ded3

Please sign in to comment.