Skip to content

Commit

Permalink
Fixes for Docker and CI
Browse files Browse the repository at this point in the history
  • Loading branch information
AltGr committed Jul 28, 2021
1 parent 66994f2 commit 46c6ce9
Show file tree
Hide file tree
Showing 10 changed files with 132 additions and 25 deletions.
2 changes: 1 addition & 1 deletion .ci-macosx.sh
Expand Up @@ -6,7 +6,7 @@ brew update
brew install pkg-config
brew install opam
brew install libev
opam init -y --compiler=4.05.0
opam init -y --compiler=4.12.0
eval $(opam env)

opam install -y -j 2 . --deps-only --locked
Expand Down
16 changes: 6 additions & 10 deletions .github/workflows/static-builds.yml
Expand Up @@ -46,20 +46,16 @@ jobs:
sw_vers
system_profiler SPSoftwareDataType
uname -a
# Need unreleased 2.1.0~rc
# - name: Retrieve opam
# run: |
# mkdir "$HOME/bin"
# wget https://github.com/ocaml/opam/releases/download/2.1.0-beta2/opam-2.1.0-beta2-x86_64-macos -O $HOME/bin/opam
# chmod a+x $HOME/bin/opam
# echo "$HOME/bin" >> $GITHUB_PATH
- name: Install latest opam
- name: Retrieve opam
run: |
brew install opam --HEAD
mkdir "$HOME/bin"
wget https://github.com/ocaml/opam/releases/download/2.1.0/opam-2.1.0-x86_64-macos -O $HOME/bin/opam
chmod a+x $HOME/bin/opam
echo "$HOME/bin" >> $GITHUB_PATH
- name: Prepare build environment
run: |
opam init -a --bare
opam switch create . ocaml-base-compiler 'dune<2' --deps-only
opam switch create . ocaml-base-compiler --deps-only
- name: Build the binaries
run: |
opam exec -- make LINKING_MODE=static
Expand Down
6 changes: 3 additions & 3 deletions Dockerfile
@@ -1,4 +1,4 @@
FROM ocaml/opam2:alpine as compilation
FROM ocaml/opam:alpine-3.13-ocaml-4.12 as compilation
LABEL Description="learn-ocaml building" Vendor="OCamlPro"

WORKDIR /home/opam/learn-ocaml
Expand Down Expand Up @@ -42,7 +42,7 @@ WORKDIR /learnocaml

COPY --from=compilation /home/opam/install-prefix/bin/learn-ocaml-client /usr/bin

ENTRYPOINT ["dumb-init","learn-ocaml-client"]
ENTRYPOINT ["dumb-init","/usr/bin/learn-ocaml-client"]

LABEL org.opencontainers.image.title="learn-ocaml-client"
LABEL org.opencontainers.image.description="learn-ocaml command-line client"
Expand All @@ -68,7 +68,7 @@ WORKDIR /home/learn-ocaml

COPY --from=compilation /home/opam/install-prefix /usr

ENTRYPOINT ["dumb-init","learn-ocaml","--sync-dir=/sync","--repo=/repository"]
ENTRYPOINT ["dumb-init","/usr/bin∕learn-ocaml","--sync-dir=/sync","--repo=/repository"]
CMD ["build","serve"]

LABEL org.opencontainers.image.title="learn-ocaml"
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile.test-client
@@ -1,7 +1,7 @@
# This Dockerfile is useful for testing purposes
# to ensure learn-ocaml-client can be built alone from learn-ocaml-client.opam

FROM ocaml/opam:alpine-3.13-ocaml-4.05 as compilation
FROM ocaml/opam:alpine-3.13-ocaml-4.12 as compilation
LABEL Description="learn-ocaml building" Vendor="OCamlPro"

WORKDIR learn-ocaml
Expand All @@ -13,7 +13,7 @@ RUN sudo chown -R opam:nogroup .
ENV OPAMYES true
RUN echo 'archive-mirrors: [ "https://opam.ocaml.org/cache" ]' >> ~/.opam/config \
&& opam repository set-url default http://opam.ocaml.org \
&& opam switch 4.05 \
&& opam switch 4.12 \
&& echo 'pre-session-commands: [ "sudo" "apk" "add" depexts ]' >> ~/.opam/config \
&& opam pin add -n -y -k path learn-ocaml-client . \
&& opam install learn-ocaml-client --deps-only
Expand Down
3 changes: 2 additions & 1 deletion Makefile
Expand Up @@ -95,7 +95,7 @@ travis: # From https://stackoverflow.com/questions/21053657/how-to-run-travis-ci
static-binaries:
./scripts/static-build.sh

BINARIES = src/main/learnocaml_client.bc src/main/learnocaml_main.bc src/main/learnocaml_server_main.exe
BINARIES = src/main/learnocaml_client.exe src/main/learnocaml_main.exe src/main/learnocaml_server_main.exe

.PHONY: detect-libs
detect-libs:
Expand All @@ -104,6 +104,7 @@ detect-libs:
baseid="detect-libs.$$$$"; echo ...; \
$(MAKE) LINKING_MODE=dynamic OCAMLPARAM="_,verbose=1" > $$baseid.log 2>&1; \
for bin in $(BINARIES); do \
rm -f "_build/default/$$bin"; \
base=$${bin#src/main/}; base=$${base%.*}; \
grep -e "'$$bin'" $$baseid.log > $$baseid.$$base.log; \
printf "%s: " "$$base"; \
Expand Down
107 changes: 107 additions & 0 deletions learn-ocaml-client.opam.locked
@@ -0,0 +1,107 @@
opam-version: "2.0"
name: "learn-ocaml-client"
version: "0.12"
synopsis: "The learn-ocaml client"
description: """\
This contains the binaries to interact with the learn-ocaml
platform from the command line."""
maintainer: "Yann Régis-Gianas"
authors: [
"Benjamin Canou (OCamlPro)"
"Çağdaş Bozman (OCamlPro)"
"Grégoire Henry (OCamlPro)"
"Louis Gesbert (OCamlPro)"
"Pierrick Couderc (OCamlPro)"
]
license: "MIT"
homepage: "https://github.com/ocaml-sf/learn-ocaml"
bug-reports: "https://github.com/ocaml-sf/learn-ocaml/issues"
depends: [
"angstrom" {= "0.15.0"}
"asak" {= "0.3"}
"astring" {= "0.8.5"}
"base" {= "v0.14.1"}
"base-bigarray" {= "base"}
"base-bytes" {= "base"}
"base-threads" {= "base"}
"base-unix" {= "base"}
"base64" {= "3.5.0"}
"bigarray-compat" {= "1.0.0"}
"bigstringaf" {= "0.8.0"}
"biniou" {= "1.2.1"}
"cmdliner" {= "1.0.4"}
"cohttp" {= "4.0.0"}
"cohttp-lwt" {= "4.0.0"}
"cohttp-lwt-unix" {= "4.0.0"}
"conduit" {= "1.3.0"}
"conduit-lwt" {= "1.3.0"}
"conduit-lwt-unix" {= "1.3.0"}
"conf-libssl" {= "3"}
"conf-pkg-config" {= "2"}
"conf-which" {= "1"}
"cppo" {= "1.6.7"}
"csexp" {= "1.5.1"}
"cstruct" {= "5.0.0"}
"digestif" {= "1.0.0"}
"dune" {= "2.9.0"}
"dune-configurator" {= "2.9.0"}
"easy-format" {= "1.3.2"}
"eqaf" {= "0.7"}
"ezjsonm" {= "1.1.0"}
"fieldslib" {= "v0.14.0"}
"fmt" {= "0.8.9"}
"gg" {= "0.9.3"}
"hex" {= "1.4.0"}
"ipaddr" {= "2.8.0"}
"jbuilder" {= "1.0+beta20.2"}
"js_of_ocaml" {= "3.9.0"}
"js_of_ocaml-compiler" {= "3.9.1"}
"js_of_ocaml-ppx" {= "3.9.0"}
"jsonm" {= "1.0.1"}
"logs" {= "0.7.0"}
"lwt" {= "5.4.1"}
"lwt_ssl" {= "1.1.3"}
"magic-mime" {= "1.1.3"}
"menhir" {= "20210419"}
"menhirLib" {= "20210419"}
"menhirSdk" {= "20210419"}
"mmap" {= "1.1.0"}
"num" {= "1.4"}
"ocaml" {= "4.12.0"}
"ocaml-compiler-libs" {= "v0.12.3"}
"ocaml-config" {= "2"}
"ocaml-migrate-parsetree" {= "1.8.0"}
"ocaml-options-vanilla" {= "1"}
"ocaml-syntax-shims" {= "1.0.0"}
"ocamlbuild" {= "0.14.0"}
"ocamlfind" {= "1.9.1"}
"ocp-indent-nlfork" {= "1.5.4"}
"ocp-ocamlres" {= "0.4"}
"ocplib-endian" {= "1.1"}
"ocplib-json-typed" {= "0.7.1"}
"omd" {= "1.3.1"}
"parsexp" {= "v0.14.1"}
"pprint" {= "20200410"}
"ppx_derivers" {= "1.2.1"}
"ppx_fields_conv" {= "v0.14.1"}
"ppx_sexp_conv" {= "v0.14.1"}
"ppx_tools" {= "6.3"}
"ppxlib" {= "0.15.0"}
"re" {= "1.9.0"}
"result" {= "1.5"}
"seq" {= "0.2.2"}
"sexplib" {= "v0.14.0"}
"sexplib0" {= "v0.14.0"}
"ssl" {= "0.5.5"}
"stdlib-shims" {= "0.3.0"}
"stringext" {= "1.6.0"}
"topkg" {= "1.0.3"}
"uchar" {= "0.0.2"}
"uri" {= "4.2.0"}
"uri-sexp" {= "4.2.0"}
"uutf" {= "1.0.2"}
"vg" {= "0.9.4"}
"yojson" {= "1.7.0"}
]
build: ["dune" "build" "@install" "-p" name "-j" jobs]
dev-repo: "git+https://github.com/ocaml-sf/learn-ocaml"
1 change: 0 additions & 1 deletion learn-ocaml.opam.locked
Expand Up @@ -74,7 +74,6 @@ depends: [
"mmap" {= "1.1.0"}
"num" {= "1.4"}
"ocaml" {= "4.12.0"}
"ocaml-base-compiler" {= "4.12.0"}
"ocaml-compiler-libs" {= "v0.12.3"}
"ocaml-config" {= "2"}
"ocaml-migrate-parsetree" {= "1.8.0"}
Expand Down
6 changes: 3 additions & 3 deletions scripts/static-build.sh
Expand Up @@ -10,11 +10,11 @@ cd $(dirname "$0")/..
set -o pipefail
git ls-files -z | xargs -0 tar c | \
docker run --rm -i \
ocamlpro/ocaml:4.05 \
ocamlpro/ocaml:4.12-2021-07-25 \
sh -uexc \
'tar x >&2 &&
sudo apk add openssl-libs-static >&2 &&
opam switch create . ocaml-system "dune<2" --deps-only >&2 &&
sudo apk add openssl-libs-static bash >&2 &&
opam switch create . ocaml-system --deps-only --locked >&2 &&
opam exec make LINKING_MODE=static >&2 &&
tar c -hC _build/install/default/bin .' | \
tar vx
4 changes: 2 additions & 2 deletions src/main/dune
Expand Up @@ -56,12 +56,12 @@
(rule
(targets linking_main.sexp)
(action (with-stdout-to %{targets}
(run ./linking_flags.sh %{env:LINKING_MODE=dynamic} %{ocaml-config:system} laolao_stubs threads camlrun))))
(run ./linking_flags.sh %{env:LINKING_MODE=dynamic} %{ocaml-config:system} checkseum_c_stubs threads camlrun))))
(rule
(targets linking_client.sexp)
(action (with-stdout-to %{targets}
(run ./linking_flags.sh %{env:LINKING_MODE=dynamic} %{ocaml-config:system} threads camlrun))))
(rule
(targets linking_server.sexp)
(action (with-stdout-to %{targets}
(run ./linking_flags.sh %{env:LINKING_MODE=dynamic} -- laolao_stubs threadsnat))))
(run ./linking_flags.sh %{env:LINKING_MODE=dynamic} -- checkseum_c_stubs threadsnat))))
8 changes: 6 additions & 2 deletions src/main/linking_flags.sh
Expand Up @@ -43,25 +43,29 @@ case $(uname -s) in
Linux)
case $(. /etc/os-release && echo $ID) in
alpine)
COMMON_LIBS="camlstr base_stubs ssl_threads_stubs ssl crypto cstruct_stubs lwt_unix_stubs bigarray unix c"
COMMON_LIBS="camlstr ssl_threads_stubs ssl crypto cstruct_stubs bigstringaf_stubs lwt_unix_stubs unix c"
# `m` and `pthread` are built-in musl
echo '(-noautolink'
echo ' -verbose'
echo ' -cclib -Wl,-Bstatic'
echo ' -cclib -static-libgcc'
# checkseum requires an additional `-L` argument
ocamlfind query -l-format checkseum.c
for l in $EXTRA_LIBS $COMMON_LIBS; do
echo " -cclib -l$l"
done
echo ' -cclib -static)'
;;
*)
echo "Error: static linking is only supported in Alpine, to avoids glibc constraints" >&2
echo "Error: static linking is only supported in Alpine, to avoids glibc constraints (use scripts/static-build.sh to build through an Alpine Docker container)" >&2
exit 3
esac
;;
Darwin)
COMMON_LIBS="camlstr base_stubs ssl_threads_stubs /usr/local/opt/openssl/lib/libssl.a /usr/local/opt/openssl/lib/libcrypto.a cstruct_stubs lwt_unix_stubs bigarray unix"
# `m` and `pthread` are built-in in libSystem
echo '(-noautolink'
echo ' -verbose'
for l in $EXTRA_LIBS $COMMON_LIBS; do
if [ "${l%.a}" != "${l}" ]; then echo " -cclib $l"
else echo " -cclib -l$l"
Expand Down

0 comments on commit 46c6ce9

Please sign in to comment.