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

Can't deploy apostroheCMS via Docker Compose #4645

Open
FuckingToasters opened this issue Jul 18, 2024 · 5 comments
Open

Can't deploy apostroheCMS via Docker Compose #4645

FuckingToasters opened this issue Jul 18, 2024 · 5 comments
Labels

Comments

@FuckingToasters
Copy link

Hello, so for some reason, i can't seem to deploy the docker container, i've cloed the full reposetory and manually added the build-assents.sh script in the scripts Folder.

Here the Dockerfile:

FROM node:lts-alpine3.15

WORKDIR /srv/www/apostrophe

RUN chown -R node: /srv/www/apostrophe
USER node

COPY --chown=node package*.json /srv/www/apostrophe/
RUN npm install

ENV NODE_ENV=production
RUN npm ci

COPY --chown=node . /srv/www/apostrophe/

RUN ./scripts/build-assets.sh

CMD ["node", "app.js"]

Here the build-assents.sh script:

#!/bin/sh

export APOS_RELEASE_ID=`cat /dev/urandom |env LC_CTYPE=C tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1`

echo $APOS_RELEASE_ID > ./release-id

node app @apostrophecms/asset:build

I've never written an single line of Javascript myself but from the Error logs i'm seeing, it can't find module app and app.js.
I changed it to index.js which seem to have resolvd the error and it seemed at first glance, that everythign worked as intented now, but hold on, i tried Checking the logs and got Nothing, i then checked running docker containers and found out, that the Apostrophe container was Always in restarting state.

I then went ahead and wanted to check the MongoDB logs, seem like that the MongoDB container either never started or instantly stopped.

I have to admit that i made some slight ajustments to the compose file to fit my Needs:

  mongodb-apostrophe:
    image: mongo:4.4.14
    #ports:
      #- "27018:27018"
    #volumes:
      #- /data/db
    volumes:
      - mongodb_apostrophe_data:/data/db
    networks:
      - revproxy

  apostrophe:
    container_name: apostropheCMS
    restart: always
    #build: .
    build:
      context: /docker/apostrophe/setup
      dockerfile: Dockerfile.compose
    #ports:
      #- "3000:3000"
    networks:
      - revproxy
    #volumes:
      #- ./data/uploads:/app/public/uploads
      #- ./data/backups:/app/backups
    volumes:
      - apostrophe_uploads:/app/public/uploads
      - apostrophe_backups:/app/backups
    environment:
      - APOS_MONGODB_URI=mongodb://mongodb-apostrophe:27017/db
    depends_on:
      - mongodb-apostrophe

volumes:
  # mongodb volumes
  mongodb_apostrophe_data:
    driver: local
    driver_opts:
      type: none
      o: bind
      device: /docker/apostrophe/mongodb_data

  # service volumes
  apostrophe_uploads:
    driver: local
    driver_opts:
      type: none
      o: bind
      device: /docker/apostrophe/uploads
  apostrophe_backups:
    driver: local
    driver_opts:
      type: none
      o: bind
      device: /docker/apostrophe/backups

networks:
  revproxy:
    external: true

I hope somebody here can help me with this issue:

Thanks in Advance,

Regards,
FuckingToasters

@BoDonkey
Copy link
Contributor

Is your project based on one of the starter kits, or completely custom?

@FuckingToasters
Copy link
Author

Is your project based on one of the starter kits, or completely custom?

I looked at the docs and took note of the build-assents.sh script, Dockerfile and docker-compose.yml: https://docs.apostrophecms.org/cookbook/using-docker.html

I then compared the docker compose file from the docs to the compose file i use for my services (no exposed ports, different way of volume mounting, inside docker network etc.)

As stated above, Containers seemd to have started successfully so i don't think that the issue lies in my spefific compose file.

@BoDonkey
Copy link
Contributor

What does this line mean, " i've cloed the full repository". What full repository?

@FuckingToasters
Copy link
Author

FuckingToasters commented Jul 19, 2024

What does this line mean, " i've cloed the full repository". What full repository?

I had a typo there, i meant cloned.

It didn't seemd to me that there was an ready built image avaiable on dockerhup which is why i cloned this repo https://github.com/apostrophecms/apostrophe

I've now took the neccecary files from https://github.com/apostrophecms/apostrophe-boilerplate/tree/main and started the deployment. It have a Tracelog when running the file:

 => ERROR [apostrophe 8/8] RUN ./scripts/build-assets.sh                  31.8s
------
 > [apostrophe 8/8] RUN ./scripts/build-assets.sh:
31.78 ERROR: There was an issue connecting to the database. Is it running?
31.79 /srv/www/apostrophe/node_modules/apostrophe/index.js:78
31.79         throw err;
31.79         ^
31.79
31.79 MongoServerSelectionError: connect ECONNREFUSED 127.0.0.1:27017
31.79     at Topology.selectServer (/srv/www/apostrophe/node_modules/mongodb/lib/sdam/topology.js:303:38)
31.79     at async Topology._connect (/srv/www/apostrophe/node_modules/mongodb/lib/sdam/topology.js:196:28)
31.79     at async Topology.connect (/srv/www/apostrophe/node_modules/mongodb/lib/sdam/topology.js:158:13)
31.79     at async topologyConnect (/srv/www/apostrophe/node_modules/mongodb/lib/mongo_client.js:204:17)
31.79     at async TinselMongoClient._connect (/srv/www/apostrophe/node_modules/mongodb/lib/mongo_client.js:217:13)
31.79     at async TinselMongoClient.connect (/srv/www/apostrophe/node_modules/mongodb/lib/mongo_client.js:142:13) {
31.79   reason: TopologyDescription {
31.79     type: 'Unknown',
31.79     servers: Map(1) {
31.79       '127.0.0.1:27017' => ServerDescription {
31.79         address: '127.0.0.1:27017',
31.79         type: 'Unknown',
31.79         hosts: [],
31.79         passives: [],
31.79         arbiters: [],
31.79         tags: {},
31.79         minWireVersion: 0,
31.79         maxWireVersion: 0,
31.79         roundTripTime: -1,
31.79         minRoundTripTime: 0,
31.79         lastUpdateTime: 1533662257,
31.79         lastWriteDate: 0,
31.79         error: MongoNetworkError: connect ECONNREFUSED 127.0.0.1:27017
31.79             at connectionFailureError (/srv/www/apostrophe/node_modules/mongodb/lib/cmap/connect.js:353:20)
31.79             at Socket.<anonymous> (/srv/www/apostrophe/node_modules/mongodb/lib/cmap/connect.js:268:44)
31.79             at Object.onceWrapper (node:events:628:26)
31.79             at Socket.emit (node:events:513:28)
31.79             at emitErrorNT (node:internal/streams/destroy:151:8)
31.79             at emitErrorCloseNT (node:internal/streams/destroy:116:3)
31.79             at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
31.79           [Symbol(errorLabels)]: Set(1) { 'ResetPool' },
31.79           [cause]: Error: connect ECONNREFUSED 127.0.0.1:27017
31.79               at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1300:16) {
31.79             errno: -111,
31.79             code: 'ECONNREFUSED',
31.79             syscall: 'connect',
31.79             address: '127.0.0.1',
31.79             port: 27017
31.79           }
31.79         },
31.79         topologyVersion: null,
31.79         setName: null,
31.79         setVersion: null,
31.79         electionId: null,
31.79         logicalSessionTimeoutMinutes: null,
31.79         primary: null,
31.79         me: null,
31.79         '$clusterTime': null
31.79       }
31.79     },
31.79     stale: false,
31.79     compatible: true,
31.79     heartbeatFrequencyMS: 10000,
31.79     localThresholdMS: 15,
31.79     setName: null,
31.79     maxElectionId: null,
31.79     maxSetVersion: null,
31.79     commonWireVersion: 0,
31.79     logicalSessionTimeoutMinutes: null
31.79   },
31.79   code: undefined,
31.79   [Symbol(errorLabels)]: Set(0) {},
31.79   [cause]: MongoNetworkError: connect ECONNREFUSED 127.0.0.1:27017
31.79       at connectionFailureError (/srv/www/apostrophe/node_modules/mongodb/lib/cmap/connect.js:353:20)
31.79       at Socket.<anonymous> (/srv/www/apostrophe/node_modules/mongodb/lib/cmap/connect.js:268:44)
31.79       at Object.onceWrapper (node:events:628:26)
31.79       at Socket.emit (node:events:513:28)
31.79       at emitErrorNT (node:internal/streams/destroy:151:8)
31.79       at emitErrorCloseNT (node:internal/streams/destroy:116:3)
31.79       at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
31.79     [Symbol(errorLabels)]: Set(1) { 'ResetPool' },
31.79     [cause]: Error: connect ECONNREFUSED 127.0.0.1:27017
31.79         at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1300:16) {
31.79       errno: -111,
31.79       code: 'ECONNREFUSED',
31.79       syscall: 'connect',
31.79       address: '127.0.0.1',
31.79       port: 27017
31.79     }
31.79   }
31.79 }
31.79
31.79 Node.js v18.12.1
------
failed to solve: process "/bin/sh -c ./scripts/build-assets.sh" did not complete successfully: exit code: 1
root@cyan-mosquito-96238 [10:01:05] [~/docker-compose]
-> #

Note that my mongodb instance is isnide the same docker network (so accessable by apotrospheCMS, yet it seem to look at localhost and iÄm not sure, where i can change it.

localhost:27017 is wrong, it needs to be mongodb-apostrophe:27017

@BoDonkey
Copy link
Contributor

So - the apostrophe-boilerplate repo is for an older version of Apostrophe. You are getting closer though. The Apostrophe repo is the code for the core of an ApostropheCMS project. As it shows in this documentation (https://docs.apostrophecms.org/cookbook/using-docker.html#apostrophe-project-setup) you should start from a starter kit like this one: https://github.com/apostrophecms/starter-kit-essentials or this one https://github.com/apostrophecms/public-demo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants