Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: use alpine for parent image, not nimlang/nim #64

Merged
merged 6 commits into from
Apr 26, 2021
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
*
!bin/install_nim.sh
!bin/run.sh
!src/runner.nim
!src/unittest_json.nim
Expand Down
14 changes: 14 additions & 0 deletions .github/workflows/shellcheck.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: shellcheck

on: [push, pull_request, workflow_dispatch]

jobs:
shellcheck:
name: Run shellcheck on scripts
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@5a4ac9002d0be2fb38bd78e4b4dbde5606d7042f # 2.3.4

- name: Run shellcheck
uses: ludeeus/action-shellcheck@94e0aab03ca135d11a35e5bfc14e6746dc56e7e9 # 1.1.0
38 changes: 29 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,17 +1,37 @@
ARG REPO=nimlang/nim
ARG IMAGE=1.4.4-alpine-slim@sha256:5c82efe7f3afffe4781f3f127d28c21ecb705dc964cc5434fee98feafd63d2d7
FROM ${REPO}:${IMAGE} AS builder
ARG REPO=alpine
ARG IMAGE=3.13.5@sha256:def822f9851ca422481ec6fee59a9966f12b351c62ccb9aca841526ffaa9f748
FROM ${REPO}:${IMAGE} AS base
# We can't reliably pin the package versions on Alpine, so we ignore the linter warning.
# See https://gitlab.alpinelinux.org/alpine/abuild/-/issues/9996
# hadolint ignore=DL3018
RUN apk add --no-cache \
gcc \
musl-dev

FROM base AS nim_builder
COPY bin/install_nim.sh /build/
# hadolint ignore=DL3018
RUN apk add --no-cache --virtual=.build-deps \
curl \
tar \
xz \
&& sh /build/install_nim.sh \
&& apk del .build-deps

FROM base AS runner_builder
COPY --from=nim_builder /nim/ /nim/
COPY src/runner.nim /build/
COPY src/unittest_json.nim /build/
RUN nim c -d:release -d:lto -d:strip /build/runner.nim
RUN /nim/bin/nim c -d:release -d:lto -d:strip /build/runner.nim

FROM ${REPO}:${IMAGE}
# We can't reliably pin the `pcre` version here, so we ignore the linter warning.
# See https://gitlab.alpinelinux.org/alpine/abuild/-/issues/9996
FROM base
COPY --from=nim_builder /nim/ /nim/
# hadolint ignore=DL3018
RUN apk add --no-cache pcre
RUN apk add --no-cache \
pcre \
&& ln -s /nim/bin/nim /usr/local/bin/nim
WORKDIR /opt/test-runner/
COPY --from=builder /build/runner bin/
COPY --from=runner_builder /build/runner bin/
COPY bin/run.sh bin/
COPY src/unittest_json.nim src/
ENTRYPOINT ["/opt/test-runner/bin/run.sh"]
25 changes: 25 additions & 0 deletions bin/install_nim.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash

set -ex

readonly ARCHIVE_FILENAME='nim.tar.xz'
readonly NIM_VERSION='1.4.4'
readonly BUILD_DIR='/build/nim'
readonly INSTALL_DIR='/nim/'
mkdir -p "${BUILD_DIR}"

(
cd "${BUILD_DIR}" || exit
curl -sSfL -o "${ARCHIVE_FILENAME}" "https://nim-lang.org/download/nim-${NIM_VERSION}.tar.xz"
tar --strip-components=1 -xf "${ARCHIVE_FILENAME}"
sh build.sh
rm -r c_code "${ARCHIVE_FILENAME}"

bin/nim c --skipUserCfg --skipParentCfg koch.nim
./koch boot -d:release -d:leanCompiler

mkdir -p "${INSTALL_DIR}"
mv bin config lib "${INSTALL_DIR}"
)

rm -r "${BUILD_DIR}"