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

Update docker build to use mongo-express repo #108

Merged
merged 9 commits into from
Jan 3, 2024

Conversation

BlackthornYugen
Copy link
Member

@BlackthornYugen BlackthornYugen commented Jan 2, 2024

I don't have permission to push to fitzrev/fix-build so I created this for now for reference. See #107

This change will build from the mongo-express repo instead of using the version deployed to NPM. It also fixes a bug in generate-stackbrew-library.sh

@BlackthornYugen BlackthornYugen self-assigned this Jan 3, 2024
@BlackthornYugen BlackthornYugen changed the title DRAFT: Update docker build Update docker build to use mongo-express repo Jan 3, 2024
+ Multi-stage build
+ Remove debug echo
+ Remove /Dockerfile
@rtritto
Copy link
Member

rtritto commented Jan 3, 2024

I got:

[FATAL tini (2)] exec /docker-entrypoint.sh failed: Permission denied

Fixed in Dockerfile adding RUN chmod +x /docker-entrypoint.sh after COPY docker-entrypoint.sh /


Instead of copy all /app content, should we copy only these?

.yarn
lib
node_modules
public
.yarnrc.yml
app.js
build-assets.json
config.default.js
package.json
webpack.config.js
yarn.lock

In future we can consider to produce a dist folder to use for copy (builds of Docker image and npm).

+ chmod +x entrypoint sh
+ Remove unneeded files
@BlackthornYugen
Copy link
Member Author

I thought that I tested that it was working last night; but maybe I forgot to build the latest changes or something. Now I can see a message that looks mostly good (except it says version 1.0.0):

2024-01-03 07:59:53 No custom config.js found, loading config.default.js
2024-01-03 07:59:53 Welcome to mongo-express 1.0.0
2024-01-03 07:59:53 ------------------------
2024-01-03 07:59:53 
2024-01-03 07:59:53 
2024-01-03 07:59:54 Mongo Express server listening at http://localhost:8081
2024-01-03 07:59:54 Wed, 03 Jan 2024 12:59:54 GMT express-session deprecated req.secret; provide secret option at file:/app/lib/router.js:84:17
2024-01-03 07:59:54 Basic authentication is disabled. It is recommended to set the useBasicAuth to true in the config.js.

But when I try to reach the server I get no response:

curl localhost:8081 --verbose --ipv4
*   Trying 127.0.0.1:8081...
* Connected to localhost (127.0.0.1) port 8081
> GET / HTTP/1.1
> Host: localhost:8081
> User-Agent: curl/8.4.0
> Accept: */*
> 
* Empty reply from server
* Closing connection
curl: (52) Empty reply from server

@BlackthornYugen
Copy link
Member Author

My current workflow:

  1. Change something in the template
  2. Apply the template with
bash -x ./update.sh 1.0
  1. Build any of the dockerfiles tagged as mongo-express
docker build --tag mongo-express 1.0/20-alpine3.18
  1. Update compose
docker-compose up -d
  1. Test
curl localhost:8081 --verbose --ipv4

Moved the definition of `ME_CONFIG_*` environment variables from the
build stage to the final stage in multiple Dockerfiles and the template. They were missing from the final image.
- Included 'css' and 'build' directories in retention during cleanup
- Broadened file retention patterns to all .json, .js, and .log files
- Removed and logged irrelevant files and directories to respective
'removed-files.log' and 'removed-dirs.log'
@BlackthornYugen
Copy link
Member Author

@rtritto @shakaran can you double check that I haven't removed any files that shouldn't have been removed?

I think manifest.yml was only for direct cloud foundry deployments, is it needed for the docker image?

cypress.config.mjs is just for tests I think?

docker run -it --rm mongo-express sh -c 'tail -n30 *.log'
==> removed-dirs.log <==
The following folders were removed to save space:
./.github
./cypress
./.bluemix
./.nyc_output
./test
./.git

==> removed-files.log <==
The following files were removed to save space:
./.gitignore
./.eslintrc.yml
./HISTORY.md
./SECURITY.md
./.gitattributes
./.mocharc.yml
./README.md
./manifest.yml
./.eslintignore
./Dockerfile
./.npmignore
./.dockerignore
./.cfignore
./cypress.config.mjs

@BlackthornYugen
Copy link
Member Author

Removing the folders saves 1MB of space but the files don't really save much, just makes it cleaner. Maybe we should put off this optimization until a future release so there are not any unintended consequences. The difference is like... 281MB vs 282MB.

Focus on stability, optimizations like this could be risky.
@rtritto
Copy link
Member

rtritto commented Jan 3, 2024

Why RUN npm version "$(git describe --tags --dirty)" --no-git-tag-version is needed? yarn is used as package manager.


Removing the folders saves 1MB of space but the files don't really save much, just makes it cleaner. Maybe we should put off this optimization until a future release so there are not any unintended consequences. The difference is like... 281MB vs 282MB.

Yes, in this PR, we can choose to not ignore other files.

@BlackthornYugen
Copy link
Member Author

Why RUN npm version "$(git describe --tags --dirty)" --no-git-tag-version is needed? yarn is used as package manager.

I'm just using NPM to change the version in package.json. The yarn version command doesn't seem to let me do this. with a full version, it wants to bump major/minor or patch. Do you know the syntax?

@BlackthornYugen
Copy link
Member Author

Why RUN npm version "$(git describe --tags --dirty)" --no-git-tag-version is needed? yarn is used as package manager.

If we don't like using npm for this, we can use jq, but I can't figure out how to do it with yarn. Here's how it might be done with jq:

RUN jq '.version=$VERSION' package.json --arg VERSION "$(git describe --tags --dirty)" | sponge package.json

or without sponge

RUN jq '.version=$VERSION' package.json --arg VERSION "$(git describe --tags --dirty)" > package.json.new ; \
    mv package.json.new package.json

@rtritto
Copy link
Member

rtritto commented Jan 3, 2024

Maybe RUN yarn version "$(git describe --tags --dirty)" works.

@BlackthornYugen
Copy link
Member Author

Maybe RUN yarn version "$(git describe --tags --dirty)" works.

Tried that but it doesn't work in the build at the moment.

 > [builder 5/7] RUN yarn version "$(git describe --tags --dirty)":
0.616 Usage Error: No ancestor could be found between any of HEAD and master, origin/master, upstream/master, main, origin/main, upstream/main
0.616 
0.616 $ yarn version [-d,--deferred] [-i,--immediate] <strategy>
------
Dockerfile:18
--------------------
  16 |     
  17 |     # RUN jq '.version=$VERSION' package.json --arg VERSION "$(git describe --tags --dirty)" | sponge package.json
  18 | >>> RUN yarn version "$(git describe --tags --dirty)"
  19 |     RUN yarn install
  20 |     RUN yarn build
--------------------
ERROR: failed to solve: process "/bin/sh -c yarn version \"$(git describe --tags --dirty)\"" did not complete successfully: exit code: 1

It works locally but it's doing extra stuff too?

mongo-express git:(release/v1.0.2) ✗ yarn version "$(git describe --tags --dirty)"
➤ YN0000: mongo-express@workspace:.: Bumped to 1.0.2-1-g5aaff6f-dirty

➤ YN0000: ┌ Resolution step
➤ YN0060: │ mongo-express@workspace:. provides babel-loader (pc43ad) with version 9.1.2, which doesn't satisfy what @cypress/code-coverage and some of its descendants request
➤ YN0000: │ Some peer dependencies are incorrectly met; run yarn explain peer-requirements <hash> for details, where <hash> is the six-letter p-prefixed code
➤ YN0000: └ Completed
➤ YN0000: ┌ Fetch step
➤ YN0000: └ Completed
➤ YN0000: ┌ Link step
➤ YN0007: │ cypress@npm:12.5.1 must be built because it never has been before or the last one failed
➤ YN0007: │ mongodb-memory-server@npm:8.11.4 must be built because it never has been before or the last one failed
➤ YN0007: │ es5-ext@npm:0.10.62 must be built because it never has been before or the last one failed
➤ YN0007: │ spawn-sync@npm:1.0.15 must be built because it never has been before or the last one failed
➤ YN0007: │ pre-commit@npm:1.2.2 must be built because it never has been before or the last one failed
➤ YN0000: └ Completed in 19s 996ms
➤ YN0000: Done with warnings in 20s 294ms
➜  mongo-express git:(release/v1.0.2) ✗ cat package.json 
{
  "version": "1.0.2-1-g5aaff6f-dirty",
...

@BlackthornYugen
Copy link
Member Author

If I have it checkout the release branch instead of the tag, the package.json will be correct already. I'll try that.

Copy link
Member

@rtritto rtritto left a comment

Choose a reason for hiding this comment

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

LGTM!

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.

3 participants