Skip to content

Commit

Permalink
Repair docker workflow (#85)
Browse files Browse the repository at this point in the history
* Fixed build error while using the *Docker workflow*

I was faced with this error after running *docker-compose up -d
--build*.

```
Configuring postgresql-libpq-0.9.4.3...
setup: The program 'pg_config' is required but it could not be found.
```

Fixed it by installing the Postgres dev tools like pg_config inside the
Flora dev container

* Fixed the Docker workflow

- Switched the base Docker image from Buster to Bullseye so the latest
  Soufflé version (2.2) can be installed
- Installed Soufflé in the container
- Installed Tmux in the container
- Set up a nice development shell inside the Docker container. The shell
  uses ZSH, Oh-my-ZSH, and a nice welcom message. The environment variables are set
  automatically.
  • Loading branch information
gbogard authored Apr 16, 2022
1 parent d7f5e10 commit 06df8d8
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 28 deletions.
36 changes: 27 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
10 changes: 5 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
7 changes: 4 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: "3"
services:
flora-server:
build: .
container_name: flora-server
container_name: flora-server-dev-env
ports:
- "8084:8084"
volumes:
Expand All @@ -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:
12 changes: 8 additions & 4 deletions environment.docker.sh → scripts/.zshrc
100755 → 100644
Original file line number Diff line number Diff line change
@@ -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
File renamed without changes.
1 change: 0 additions & 1 deletion scripts/start-tmux.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env bash

set -euxo pipefail

tmux kill-session -t 'flora' || true
Expand Down

0 comments on commit 06df8d8

Please sign in to comment.