Skip to content

Commit 80d0d1a

Browse files
committed
Add Makefile to build a docker image using docker-compose
1 parent d14f533 commit 80d0d1a

File tree

6 files changed

+59
-0
lines changed

6 files changed

+59
-0
lines changed

Dockerfile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
FROM ubuntu:16.04
2+
3+
ENV DIRPATH /usr/local/etc
4+
5+
WORKDIR $DIRPATH
6+
7+
RUN apt-get update -y
8+
RUN apt-get install -y postgresql-client
9+
10+
COPY bin/realworld-exe /usr/local/bin/realworld-exe
11+
COPY postgresql $DIRPATH/postgresql
12+
COPY secrets $DIRPATH/secrets
13+
14+
ENTRYPOINT [ "realworld-exe" ]

Makefile

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!make
2+
include docker.env
3+
export $(shell sed 's/=.*//' docker.env)
4+
5+
$(PROJECT_BIN_DIR)/$(PROJECT_BIN):
6+
stack build --local-bin-path $(PROJECT_BIN_DIR) --copy-bins
7+
8+
build: $(PROJECT_BIN_DIR)/$(PROJECT_BIN)
9+
.PHONY: build
10+
11+
docker-build:
12+
docker-compose run --rm builder $(SRC_DIR)/docker-builder.sh
13+
14+
image:
15+
docker build -t $(IMAGE_NAME):$(IMAGE_VERSION) .
16+
docker tag $(IMAGE_NAME):$(IMAGE_VERSION) $(IMAGE_NAME):latest
17+
18+
clean:
19+
rm -f $(PROJECT_BIN_DIR)/* || true
20+
rm *.cabal # remove hpack generated cabal file
21+
stack clean

bin/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
*
2+
*/
3+
!.gitignore

docker-builder.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/bash
2+
3+
apt-get update -y
4+
sudo apt-get install -y postgresql postgresql-contrib
5+
6+
cd $SRC_DIR
7+
8+
make build

docker-compose.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
version: '3'
2+
services:
3+
builder:
4+
image: 'fpco/stack-build:lts-11.10'
5+
volumes:
6+
- ./:/usr/local/src:rw
7+
env_file:
8+
- docker.env

docker.env

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
SRC_DIR=/usr/local/src
2+
PROJECT_BIN_DIR=bin
3+
PROJECT_BIN=realworld-exe
4+
IMAGE_VERSION=1
5+
IMAGE_NAME=haskell-scotty-realworld-example-app

0 commit comments

Comments
 (0)