The other day, I was able to run spago repl
on the Docker container, so this time I will check the build and execution of the project created with spago init
.
Running PureScript on Docker container-Qiita
Windows10 Home Edition
VirtualBox 6.1.16
docker-machine.exe version 0.16.1, build cce350d7
# Docker Host OS (CoreOS)
$ uname -a
Linux default 4.14.154-boot2docker #1 SMP Thu Nov 14 19:19:08 UTC 2019 x86_64 GNU/Linux
Docker version 19.03.5, build 633a0ea838
docker-compose version 1.26.0, build d4451659
Prepare docker-compose.yml
, Dockerfile
and myapp
in the empty folder in the purescript
folder.
purescript
├── docker-compose.yml
├── Dockerfile
└── myapp
docker-compose.yml
docker-compose.yml
version: "3.7"
services:
purescript:
build:
context: .
dockerfile: Dockerfile
target: "purescript"
image: takaya030/purescript
command: "true"
app:
build:
context: .
dockerfile: Dockerfile
target: "pure-app"
image: takaya030/pure-app
volumes:
- ./myapp:/home/pureuser/myapp
working_dir: /home/pureuser/myapp
command: "spago run"
Dockerfile
Dockerfile
FROM node:12 as purescript
LABEL maintainer "takaya030"
# install purescript
RUN npm install --global --unsafe-perm purescript spago
# add user
RUN userdel node && \
useradd -m -s /bin/bash pureuser
WORKDIR /home/pureuser
USER pureuser
RUN mkdir tmp && cd tmp && spago init
CMD cd tmp && spago repl
#=========================================
FROM purescript as pure-app
COPY ./myapp /home/pureuser/myapp
WORKDIR /home/pureuser/myapp
CMD ["spago","run"]
$ cd purescript
$ docker-compose build purescript
$ docker-compose build app
Check the image
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
takaya030/pure-app latest c018082fc97b 27 hours ago 1.08GB
takaya030/purescript latest fb50aeb56d04 2 days ago 1.08GB
node 12 1f560ce4ce7e 5 weeks ago 918MB
Executing the following command will create an initial project under the myapp
folder
$ docker-compose run --rm app spago init
Project file structure
$ ls -l myapp
total 4
-rwxrwxrwx 1 docker staff 2903 Nov 16 09:53 packages.dhall
-rwxrwxrwx 1 docker staff 231 Nov 16 09:53 spago.dhall
drwxrwxrwx 1 docker staff 0 Nov 16 09:57 src
drwxrwxrwx 1 docker staff 0 Nov 16 09:53 test
In my environment, the pictograms of the sample program are garbled, so I changed it as follows
myapp/src/Main.purs
module Main where
import Prelude
import Effect (Effect)
import Effect.Console (log)
main :: Effect Unit
main = do
log "Hello, PureScript"
Build with the following command
$ docker-compose run --rm app spago build
[info] Build succeeded.
If the build is successful, execute it with the following command
$ docker-compose run --rm app spago run
Hello, PureScript
-How to get started with PureScript, a pure functional scripting language-- Qiita
Recommended Posts