Skip to content

Commit

Permalink
Add a dockerfile for building and testing everything
Browse files Browse the repository at this point in the history
  • Loading branch information
mjambon committed Jun 25, 2020
1 parent a1b580d commit 2576beb
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 10 deletions.
13 changes: 13 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#
# Translated manually from .gitignore.
#

bin
**/tmp
**/_build
**/.merlin
**/*.install
_opam
node_modules
package-lock.json
tree-sitter
39 changes: 39 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#
# Reference workflow for building and testing ocaml-tree-sitter.
#
# Run with:
#
# docker build -t ocaml-tree-sitter .
#
# Enter the resulting container with:
#
# docker run -it ocaml-tree-sitter
#

FROM ocaml/opam2:debian-stable

COPY --chown=opam:opam scripts /home/opam/ocaml-tree-sitter/scripts
COPY --chown=opam:opam Makefile /home/opam/ocaml-tree-sitter/Makefile
WORKDIR /home/opam/ocaml-tree-sitter
RUN sudo chown opam:opam .

# Slow steps that mostly download and build external stuff.
RUN ./scripts/setup-node
RUN ./scripts/setup-opam
COPY --chown=opam:opam tree-sitter.opam /home/opam/ocaml-tree-sitter/tree-sitter.opam
RUN opam exec -- make setup

# Copy the rest, which changes often.
COPY --chown=opam:opam . /home/opam/ocaml-tree-sitter

# 'opam exec -- CMD' sets environment variables (PATH etc.) and runs
# command CMD in this environment.
# This is equivalent to 'eval $(opam env)' which normally goes into
# ~/.bashrc or similar.
#
RUN opam exec -- make
RUN opam exec -- make install

# FIXME Why does ld not search /usr/local/lib despite it being listed
# in /etc/ld.so.conf.d/libc.conf ?
RUN LD_LIBRARY_PATH=/usr/local/lib opam exec -- make test
10 changes: 2 additions & 8 deletions scripts/install-tree-sitter-cli
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,8 @@
#
set -eu

project_root=$(git rev-parse --show-toplevel)

# Install node modules at the project root.
# Install node modules. Should be done at the project root.
# The tree-sitter executable will be in 'node_modules/.bin'.
(
cd "$project_root"

npm install \
npm install \
tree-sitter \
tree-sitter-cli
)
2 changes: 0 additions & 2 deletions scripts/install-tree-sitter-lib
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
#
set -eu

project_root=$(git rev-parse --show-toplevel)

if [[ ! -e tree-sitter ]]; then
git clone --depth 1 https://github.com/tree-sitter/tree-sitter.git
fi
Expand Down
23 changes: 23 additions & 0 deletions scripts/setup-node
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#! /usr/bin/env bash
#
# Install Node.js so that we can install the tree-sitter command-line
# interface. Intended for Debian/Ubuntu only.
#

cat > ~/.npmrc <<EOF
prefix = ~/.node
EOF

cat >> ~/.bashrc <<EOF
export PATH="$HOME/.node/bin:$PATH"
export NODE_PATH="$HOME/.node/lib/node_modules:$NODE_PATH"
export MANPATH="$HOME/.node/share/man:$MANPATH"
EOF

sudo apt-get update
sudo apt-get install -y nodejs npm

npm install npm -g

# Local install into node_modules/
npm install node-gyp
17 changes: 17 additions & 0 deletions scripts/setup-opam
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#! /usr/bin/env bash
#
# Complete the opam setup already in place in the docker image
# ocaml/opam2:debian-stable.
#

sudo apt-get update
sudo apt-get install -y m4

opam switch 4.09

if ! (opam repo list | grep -q http); then
opam repo add --all -k git github \
https://github.com/ocaml/opam-repository.git
fi

opam update
1 change: 1 addition & 0 deletions tree-sitter.opam
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ depends: [
"ocaml"
"ppx_deriving"
"ppx_sexp_conv"
"sexplib"
"tsort" {>= "2.0"}
]

Expand Down

0 comments on commit 2576beb

Please sign in to comment.