Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop using multiple dockerfiles and start specifying targets for multi-stage builds #589

Open
falgon opened this issue Sep 17, 2024 · 0 comments

Comments

@falgon
Copy link
Owner

falgon commented Sep 17, 2024

  • The following two:
  • Make multi-stage builds happen within the Dockerfile, eg.
    FROM ubuntu:24.03 AS base
    # Install dependencies from apt and setup ghcup (do not forget to get chromium browser...)
    
    # for development...
    FROM base AS dev
    WORKDIR /src
    RUN --mount=type=bind,source=.,dst=.,rw \
        stack --no-terminal --allow-different-user build --only-dependencies
    
    # build stage (for app)
    FROM dev AS build
    WORKDIR /src
    RUN --mount=type=bind,source=.,dst=.,rw \
        mkdir /dist && stack --no-terminal --allow-different-user install --local-bin-path /dist
    
    # for site and spa
    FROM alpine:latest AS apps
    WORKDIR /app
    RUN apk update && apk upgrade --no-cache && apk add --no-cache gmp-dev libffi-dev zlib-dev chromium
    COPY --from=build /dist/site /app/site
    COPY --from=build /dist/spa /app/spa
    ENV PATH /app:$PATH
    EXPOSE 8888
    docker-compose.yml, eg.
    services:
        build:
            image: $ROKI_WEB_ENV_IMAGE_NAME $ROKI_WEB_ENV_IMAGE_TAG
            container_name: roki-web-build
            volumes:
                - "../contents:/home/rw-c/bin/contents"
            ports:
                - "8888:8888"
            working_dir: /home/rw-c/bin
            build:
                context: ../
                dockerfile: ./Dockerfile
                target: apps # important
            command: site build --preview
        preview:
            # ditto...
            build:
                context: ../
                dockerfile: ./Dockerfile
                target: apps
            command: site watch --preview --port 8888 --host 0.0.0.0
    # ditto...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant