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: slim docker image to 154Mb #5248

Merged
merged 3 commits into from
Dec 22, 2018
Merged

docker: slim docker image to 154Mb #5248

merged 3 commits into from
Dec 22, 2018

Conversation

flovilmart
Copy link
Contributor

No description provided.

@flovilmart
Copy link
Contributor Author

@barakbd can you tell me if this version of the dockerfile work for you?

@codecov
Copy link

codecov bot commented Dec 18, 2018

Codecov Report

Merging #5248 into master will decrease coverage by 0.02%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #5248      +/-   ##
==========================================
- Coverage   93.88%   93.86%   -0.03%     
==========================================
  Files         123      123              
  Lines        8965     8965              
==========================================
- Hits         8417     8415       -2     
- Misses        548      550       +2
Impacted Files Coverage Δ
src/RestWrite.js 92.88% <0%> (-0.37%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 631b168...800a8be. Read the comment docs.

acinader
acinader previously approved these changes Dec 18, 2018
Copy link
Contributor

@acinader acinader left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm. easy to read and understand.

@barakbd
Copy link

barakbd commented Dec 18, 2018

@flovilmart - will check soon.
You are using the lts version of Node in the Dockerfile. Is that ok? Are the unit tests always running against the lts version of Node?

@flovilmart
Copy link
Contributor Author

The tests are running against node 10. We’ll update the CI setup to effectively run always against lts

@barakbd
Copy link

barakbd commented Dec 18, 2018

There is an issue with the image built using your Dockerfile, not sure what it is.
When I call GET on localhost:1337/parse/schemas it returns:

{
    "results": []
}

But when I call that API using image parseplatform/parse-server:3.0.0 or the image built with my Dockerfile, I get:

{
    "results": [
        {
            "className": "_User",
            "fields": {
                "objectId": {
                    "type": "String"
                },
                "createdAt": {
                    "type": "Date"
                },
                "updatedAt": {
                    "type": "Date"
                },
                "ACL": {
                    "type": "ACL"
                },
                "username": {
                    "type": "String"
                },
                "password": {
                    "type": "String"
                },
                "email": {
                    "type": "String"
                },
                "emailVerified": {
                    "type": "Boolean"
                },
                "authData": {
                    "type": "Object"
                }
            },
            "classLevelPermissions": {
                "find": {
                    "*": true
                },
                "get": {
                    "*": true
                },
                "create": {
                    "*": true
                },
                "update": {
                    "*": true
                },
                "delete": {
                    "*": true
                },
                "addField": {
                    "*": true
                }
            }
        },
        {
            "className": "_Role",
            "fields": {
                "objectId": {
                    "type": "String"
                },
                "createdAt": {
                    "type": "Date"
                },
                "updatedAt": {
                    "type": "Date"
                },
                "ACL": {
                    "type": "ACL"
                },
                "name": {
                    "type": "String"
                },
                "users": {
                    "type": "Relation",
                    "targetClass": "_User"
                },
                "roles": {
                    "type": "Relation",
                    "targetClass": "_Role"
                }
            },
            "classLevelPermissions": {
                "find": {
                    "*": true
                },
                "get": {
                    "*": true
                },
                "create": {
                    "*": true
                },
                "update": {
                    "*": true
                },
                "delete": {
                    "*": true
                },
                "addField": {
                    "*": true
                }
            }
        }
    ]
}

@flovilmart
Copy link
Contributor Author

How did you mount / run it?

@barakbd
Copy link

barakbd commented Dec 18, 2018

  1. Pull branch dev from https://github.com/barakbd/parse-server-docker-compose.git
  2. line 8 in docker-compose.yml - replace the image name with the name and tag of the image you built locally
  3. In the directory where the docker-compose.yml exists - run docker-compose up
  4. Make an API call in Postman with masterKey and appId in the headers. You can get/set them in the .env file
  5. To destroy the containers, run docker-compose down

@flovilmart
Copy link
Contributor Author

flovilmart commented Dec 18, 2018

@barakbd I just ran a simple test:

from this branch run:

docker build . -t parse-server:yolo 

the run the server:

docker run -p 1337:1337 -t parse-server:yolo --appId hello --masterKey world --databaseURI mongodb://admin:[email protected]:39334/yolo

Note the database is clean and was just created before the 1st start

Then run:

$ curl -H 'X-parse-master-key: world' -H 'x-parse-application-id: hello' http://localhost:1337/parse/schemas

And I have the following result:

{"results":[{"className":"_Role","fields":{"objectId":{"type":"String"},"createdAt":{"type":"Date"},"updatedAt":{"type":"Date"},"ACL":{"type":"ACL"},"name":{"type":"String"},"users":{"type":"Relation","targetClass":"_User"},"roles":{"type":"Relation","targetClass":"_Role"}},"classLevelPermissions":{"find":{"*":true},"get":{"*":true},"create":{"*":true},"update":{"*":true},"delete":{"*":true},"addField":{"*":true}}},{"className":"_User","fields":{"objectId":{"type":"String"},"createdAt":{"type":"Date"},"updatedAt":{"type":"Date"},"ACL":{"type":"ACL"},"username":{"type":"String"},"password":{"type":"String"},"email":{"type":"String"},"emailVerified":{"type":"Boolean"},"authData":{"type":"Object"}},"classLevelPermissions":{"find":{"*":true},"get":{"*":true},"create":{"*":true},"update":{"*":true},"delete":{"*":true},"addField":{"*":true}}}]}

@barakbd-bluevine
Copy link

If it works for you then go ahead and merge to master, and build a new image for Dockerhub.

@flovilmart
Copy link
Contributor Author

@barakbd that's not the point, I am trying to avoid a regression if there is any. Did you try in another context like directly using the docker image?

@flovilmart
Copy link
Contributor Author

@barakbd I also realized the VOLUME instruction with the single quotes was malformed

JSON formatting: The list is parsed as a JSON array. You must enclose words with double quotes (") rather than single quotes (').

https://docs.docker.com/engine/reference/builder/#volume

Perhaps this was your issue

@barakbd
Copy link

barakbd commented Dec 19, 2018

I tested again, still not working when running with a local mongodb docker.
When I run with the current parse-server docker image (parseplatform/parse-server:3.0.0) I see this output from the mongodb container, which I do not see with your image:
mongo-3.6 | 2018-12-19T20:06:51.528+0000 I STORAGE [conn1] createCollection: parse_db._User with generated UUID: 1087310c-9403-44c7-b662-bd133798d8c0 mongo-3.6 | 2018-12-19T20:06:51.542+0000 I INDEX [conn1] build index on: parse_db._User properties: { v: 2, unique: true, key: { email: 1 }, name: "email_1", ns: "parse_db._User", background: true, sparse: true } mongo-3.6 | 2018-12-19T20:06:51.548+0000 I INDEX [conn3] build index on: parse_db._User properties: { v: 2, unique: true, key: { username: 1 }, name: "username_1", ns: "parse_db._User", background: true, sparse: true } mongo-3.6 | 2018-12-19T20:06:51.548+0000 I INDEX [conn3] build index done. scanned 0 total records. 0 secs mongo-3.6 | 2018-12-19T20:06:51.548+0000 I INDEX [conn1] build index done. scanned 0 total records. 0 secs mongo-3.6 | 2018-12-19T20:06:51.550+0000 I STORAGE [conn2] createCollection: parse_db._Role with generated UUID: a66f7572-fcfa-4f53-b496-b7005a995626 mongo-3.6 | 2018-12-19T20:06:51.563+0000 I INDEX [conn2] build index on: parse_db._Role properties: { v: 2, unique: true, key: { name: 1 },name: "name_1", ns: "parse_db._Role", background: true, sparse: true } mongo-3.6 | 2018-12-19T20:06:51.563+0000 I INDEX [conn2] build index done. scanned 0 total records. 0 secs

@flovilmart
Copy link
Contributor Author

Well, that doesn’t help much. What do you mean by ‘not working’? Is the Schema still the same? Are there any logs? Is the master branch showing a proper behaviour?

@barakbd
Copy link

barakbd commented Dec 19, 2018

Have you tried running it with the docker compose setup in the repo I sent?
Any way you can push your new docker image somehwere that I can pull and test?

@barakbd
Copy link

barakbd commented Dec 19, 2018

I still get

{
    "results": []
}

@flovilmart
Copy link
Contributor Author

way you can push your new docker image somehwere that I can pull and test?

I simply ran docker build . -t my-image if this doesn’t work for you then there is a problem.

What are the logs from the container when started with —verbose=1

@flovilmart
Copy link
Contributor Author

@barakbd I attempted to run your docker compose project and you can find the logs there:

https://gist.github.com/flovilmart/dfc72624d44201c6c37dabc1f640a7e9

This doesn't look good, as the DB gets killed and then restarted, at the time the server starts, the DB is not up. This doesn't look related to those changes.

@flovilmart
Copy link
Contributor Author

If you look closely to the logs, we see:

 warn: Unable to ensure uniqueness for usernames:  message=failed to connect to server [mongo:27017] on first connect [MongoNetworkError: connect ECONNREFUSED 172.18.0.2:27017], stack=MongoNetworkError: failed to connect to server [mongo:27017] on first connect [MongoNetworkError: connect ECONNREFUSED 172.18.0.2:27017]

And on a following restart:

Unable to ensure uniqueness for user email addresses:  message=there are no users authenticated, stack=MongoError: there are no users authenticated

So there seems to be an issue with your docker compose setup:

  1. the DB is not started / starting correctly
  2. the authentication to the DB is invalid

@barakbd
Copy link

barakbd commented Dec 20, 2018

It looks like you are running master. checkout dev branch and then run docker-compose up.

@flovilmart
Copy link
Contributor Author

Why don’t you try with the built image? Can you provide the logs when starting please?

@barakbd
Copy link

barakbd commented Dec 21, 2018

Which built image?
Have you tried dev branch?

@flovilmart
Copy link
Contributor Author

The image built from the repository. And no I haven’t tested the dev branch, have you? Can you provide the logs when starting up?

@flovilmart
Copy link
Contributor Author

@barakbd I tested with your dev branch, and it is still failing when running docker-compose up https://gist.github.com/flovilmart/b73b8a2ad8a7f7f10722fda28bc1105c and I achieve the same result as you executing the curl command

curl -H 'X-parse-master-key: masterKey' -H 'x-parse-application-id: appId' http://localhost:1337/parse/schemas
{"results":[]}%

However, if you ctrl+c and start a second time, you will notice that it is all good and running, so I suspect an issue in your docker compose setup which likely only occurs on first start.

@flovilmart flovilmart changed the title Better dockerfile docker: slim docker image to 154Mb Dec 22, 2018
@flovilmart flovilmart merged commit a9aff79 into master Dec 22, 2018
@flovilmart flovilmart deleted the better-dockerfile branch December 22, 2018 16:33
@ozbillwang
Copy link

ozbillwang commented Jul 8, 2019

@flovilmart @acinader @barakbd @barakbd-bluevine

Seems this PR wasn't properly tested. I currently got this error (#5778) and discovered, after rollback the base image from node:lts-alpine to node:10.16.0 (a similar Debian Linux as node:carbon) , I can successfully docker build it.

Let me know how should I go with.

By the way, the official document of package bcrypt doesn't recommend to run it in alpine (musl lib vs glibc lib)

https://github.com/kelektiv/node.bcrypt.js/wiki/Installation-Instructions#alpine-linux-based-images

UnderratedDev pushed a commit to UnderratedDev/parse-server that referenced this pull request Mar 21, 2020
* Better dockerfile

* nits

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

Successfully merging this pull request may close these issues.

5 participants