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

docker-compose mounted host paths cause problems with lib/modules #1479

Closed
airtonix opened this issue Jul 10, 2018 · 6 comments
Closed

docker-compose mounted host paths cause problems with lib/modules #1479

airtonix opened this issue Jul 10, 2018 · 6 comments

Comments

@airtonix
Copy link

airtonix commented Jul 10, 2018

Looking at how this whole thing would work in local dev, ran into public file problems. I assume it's to do with symlinks.

docker-compose.yml

version: "3.0"

services:
  app:
    build: .
    volumes:
      - ./:/app
      - /app/data
      - /app/node_modules
      - /app/public/uploads
    environment:
      MONGO_HOST: db
      MONGO_PORT: 27017
      MONGO_DB: app
    ports:
      - 3000:3000
    links:
      - db
    restart: on-failure

  db:
    image: mongo
    healthcheck:
      test: echo 'db.stats().ok' | mongo localhost:27017/app --quiet
      interval: 5s
      timeout: 2s
      retries: 3

Dockerfile

FROM node:6-alpine

# Create app directory
RUN mkdir -p /app
WORKDIR /app

# Bundle app source
COPY . /app
RUN npm install

# Mount persistent storage
VOLUME /app/data
VOLUME /app/public/uploads

EXPOSE 3000
CMD [ "npm", "start" ]

app.js

var path = require('path');

var apos = require('apostrophe')({
  shortName: '2nd-try',

  // See lib/modules for basic project-level configuration of our modules
  // responsible for serving static assets, managing page templates and
  // configuring user accounts.

  modules: {

    // Apostrophe module configuration

    // Note: most configuration occurs in the respective
    // modules' directories. See lib/apostrophe-assets/index.js for an example.
    
    // However any modules that are not present by default in Apostrophe must at
    // least have a minimal configuration here: `moduleName: {}`

    // If a template is not found somewhere else, serve it from the top-level
    // `views/` folder of the project
    'apostrophe-db': {
      uri: `mongodb://${process.env.MONGO_HOST||'localhost'}:${process.env.MONGO_PORT||27017}/${process.env.MONGO_DB||'db'}`
    },

    'apostrophe-templates': { viewsFolderFallback: path.join(__dirname, 'views') }

  }
});

package.json

{
  "name": "2nd-try",
  "version": "2.0.0",
  "description": "Minimal Apostrophe Boilerplate",
  "main": "app.js",
  "scripts": {
    "start": "node app.js",
    "docker:up": "docker-compose up",
    "docker:exec": "docker-compose exec app",
    "docker:run": "docker-compose run --rm app",
    "docker:build": "docker-compose build app",
    "app": "npm run docker:exec -- npm run start"
  },
  "repository": {
    "type": "git",
    "url": ""
  },
  "author": "P'unk Avenue",
  "license": "MIT",
  "dependencies": {
    "apostrophe": "^2.47.0"
  },
  "nodemonConfig": {
    "verbose": true,
    "ignore": [
      "locales/*.json",
      "public/modules/**/*.less",
      "public/modules/**/*.js",
      "public/uploads",
      "public/apos-minified/*.js",
      "public/css/master-*.less",
      "data"
    ],
    "ext": "json, js, html, less"
  }
}

My workstation:

applicationframehost_2018-07-10_09-14-28

$ docker -v 
Docker version 18.03.1-ce, build 9ee9f40
$ docker-compose -v
docker-compose version 1.21.1, build 7641a569

Its worth noting that the compose file mounts are designed to re-layer the /app/node_modules back on top of the host mounted app root. The /app/node_modules comes from the initial layer created by npm run docker:build.

When I try to run all this with the app mounted from the host, I get these errors:

$ npm run docker:up
...
app_1  |   LESS File error : '../modules/my-apostrophe-assets/css/site.less' wasn't found. Tried - /app/public/modules/my-apostrophe-assets/css/site.less,../modules/my-apostrophe-assets/css/site.less
app_1  |   LESS File : /app/public/css/master-anon-cjjexc6eh00000gnyrvnqo30s.less 11:0
...

The browser network tab logs show a lot of 404.

Then, when I stop the stack, change the volumes directive in the docker-compose.yml, it all works fine:

    volumes:
      - ./data:/app/data
      - ./lib:/app/lib
      - ./locales:/app/locales
      - ./scripts:/app/scripts
      - ./views:/app/views

So I guess the question here is:

  1. is it important for the /app/public directory to be in my git repo? seems not
  2. what are the directories I need to be mounting into the container during local dev? is the above enough (data, lib, locales, scripts, views) ?
  3. is there a config value that changes the behaviour of /app/public to copy instead of symlink so that files created there make sense on windows host mounted volumes?
@boutell
Copy link
Member

boutell commented Jul 10, 2018 via email

@boutell
Copy link
Member

boutell commented Jul 10, 2018 via email

@airtonix
Copy link
Author

airtonix commented Jul 11, 2018 via email

@airtonix
Copy link
Author

airtonix commented Jul 11, 2018 via email

@boutell
Copy link
Member

boutell commented Jul 11, 2018 via email

@stale
Copy link

stale bot commented Jun 19, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

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

3 participants