diff --git a/Dockerfile b/Dockerfile index 593badd5..74c0b651 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,18 +1,36 @@ # syntax=docker/dockerfile:1 -FROM haskell:8.10 +FROM gbogard/haskell-bullseye:8.10.7 # generate a working directory WORKDIR /flora-server -# copy the files relevant to build core dependencies -COPY cabal.project flora.cabal shell.nix environment.sh environment.docker.sh Makefile scripts/start-tmux.sh ./ +# install dependencies (pg_config & yarn) +RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - +RUN curl -fsSL https://deb.nodesource.com/setup_17.x | bash - +RUN echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list +RUN apt update +RUN apt install -y nodejs yarn libpq-dev mcpp wget zsh tmux -RUN cabal update -# let nix build the dependencies. This uses nix-shell to cache the setup phase. -RUN cabal build -j4 +# install soufflé +RUN wget --content-disposition https://github.com/souffle-lang/souffle/releases/download/2.2/x86_64-ubuntu-2004-souffle-2.2-Linux.deb +RUN apt install -f -y ./x86_64-ubuntu-2004-souffle-2.2-Linux.deb -# copy asset-relevant dependency files -COPY assets/package.json assets/yarn.lock assets/ -RUN make assets-deps +# configure the shell +RUN sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" +COPY scripts/shell-welcome.txt /etc/motd +COPY scripts/.zshrc /root/.zshrc +# build Haskell dependencies +COPY Makefile cabal.project flora.cabal ./ +RUN cabal build --only-dependencies -j8 + +# Compile Souffle source files +COPY cbits ./cbits +RUN make souffle + +# copy and build the assets +COPY assets ./assets +RUN make build-assets + +RUN echo $PATH > /etc/profile CMD [ "/bin/sh", "-c", "sleep 1d"] diff --git a/Makefile b/Makefile index a10d9200..e2ffc7a6 100644 --- a/Makefile +++ b/Makefile @@ -62,14 +62,14 @@ style: ## Run the code formatters (stylish-haskell, cabal-fmt, nixfmt) nix-shell: ## Enter the Nix shell @nix-shell -docker-build: ## Build the docker image - @docker-compose build - docker-start: ## Start the container cluster - @docker-compose up -d + @docker-compose up -d --build docker-enter: ## Enter the docker environment - docker-compose exec flora-server "nix-shell" + docker-compose exec flora-server "zsh" + +start-tmux: ## Start a Tmux session with hot code reloading + ./scripts/start-tmux.sh soufflé: ## Generate C++ files from the Soufflé Datalog definitions cd cbits ; souffle -g categorise.{cpp,dl} diff --git a/README.md b/README.md index 5013723b..39e0a0fa 100644 --- a/README.md +++ b/README.md @@ -79,15 +79,16 @@ you can also use `db-create` and `db-drop` to create and delete the database in ### Docker Workflow -A docker-based workflow is provided: +A docker-based workflow is provided. The idea is to develop from within a container that brings with it all dependencies, +and communicates with another container for the Postgres database. ```bash -# It's gonna take around 13 minutes the first time you build, -# run "make docker-start" the next times. -$ docker-compose up -d --build +# It's gonna take around 13 minutes the first time you build +$ make docker-start +# Once the containers are running, you can enter the development environment and start hacking $ make docker-enter -# You'll be in the docker container -(docker)$ source environment.docker.sh +# You'll be in the docker container. Environment variables are automatically set +# so you should be able to start Flora (docker)$ make nix-tmux # You'll be in a tmux session, everything should be launched # Visit localhost:8084 from your web browser to see if it all works. diff --git a/docker-compose.yml b/docker-compose.yml index b0a7dd1a..2256a2a0 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,7 +2,7 @@ version: "3" services: flora-server: build: . - container_name: flora-server + container_name: flora-server-dev-env ports: - "8084:8084" volumes: @@ -14,12 +14,13 @@ services: database: image: "postgres" container_name: database + ports: + - "5432:5432" expose: - "5432" env_file: - database.env volumes: - - database-data:/flora-server/pgdata/ - + - database-data:/var/lib/postgresql/data volumes: database-data: diff --git a/environment.docker.sh b/scripts/.zshrc old mode 100755 new mode 100644 similarity index 69% rename from environment.docker.sh rename to scripts/.zshrc index e256c55a..033fe669 --- a/environment.docker.sh +++ b/scripts/.zshrc @@ -1,9 +1,13 @@ -source environment.sh +export ZSH="$HOME/.oh-my-zsh" +ZSH_THEME="robbyrussell" -export FLORA_DB_HOST="database" +plugins=(git) +source $ZSH/oh-my-zsh.sh +source /flora-server/environment.sh +export FLORA_DB_HOST="database" export FLORA_PG_URI="postgresql://${FLORA_DB_USER}:${FLORA_DB_PASSWORD}@${FLORA_DB_HOST}:${FLORA_DB_PORT}/${FLORA_DB_DATABASE}" export FLORA_PG_CONNSTRING="host=${FLORA_DB_HOST} dbname=${FLORA_DB_DATABASE} user=${FLORA_DB_USER} password=${FLORA_DB_PASSWORD}" - - export FLORA_HTTP_PORT=8084 + +cat /etc/motd \ No newline at end of file diff --git a/scripts/nix-welcome.txt b/scripts/shell-welcome.txt similarity index 100% rename from scripts/nix-welcome.txt rename to scripts/shell-welcome.txt diff --git a/scripts/start-tmux.sh b/scripts/start-tmux.sh index 57bd4d9b..e259d8c5 100755 --- a/scripts/start-tmux.sh +++ b/scripts/start-tmux.sh @@ -1,5 +1,4 @@ #!/usr/bin/env bash - set -euxo pipefail tmux kill-session -t 'flora' || true