Skip to content

Create a docker build script #1138

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

Merged
merged 7 commits into from
Aug 8, 2023
Merged

Create a docker build script #1138

merged 7 commits into from
Aug 8, 2023

Conversation

erubboli
Copy link
Member

@erubboli erubboli commented Aug 5, 2023

This script build and pushes the docker images, it retrieve the version from the Cargo file and can be invoked by make as build_docker_images.

Copy link
Contributor

@muursh muursh left a comment

Choose a reason for hiding this comment

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

I've half tested this. I have no issues with what I see.

.dockerignore Outdated
@@ -0,0 +1,9 @@
**/target/
Copy link
Contributor

Choose a reason for hiding this comment

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

This pattern will exclude any directory named 'target' anywhere in the source tree. IMO we should only exclude the 'target' directory at the root, which is the one that cargo uses.
So, this line can be just:

target

.dockerignore Outdated
Comment on lines 2 to 9
**/*.rs.bk
**/Dockerfile
**/.dockerignore
**/.git
**/.gitignore
**/tmp
**/Cargo.lock
.docker/
Copy link
Contributor

Choose a reason for hiding this comment

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

IMO these lines are not needed (probably except for the top-level .git directory). The purpose of .dockerignore is to exclude the "heavy" or sensitive stuff that we wouldn't want to accidentally copy into the image. IMO there is no harm in copying extra small files into "builder" image.

Makefile Outdated
Comment on lines 1 to 11
.PHONY: build_docker_images

# python scripts are requiring `python3.11-venv` and `python3-pip` installed
install-pip-dependencies:
python3 -m venv env && . env/bin/activate && python3 -m pip install --upgrade pip && python3 -m pip install toml

build_docker_images: install-pip-dependencies
. env/bin/activate && python3 build-tools/docker/build.py

push_docker_images: install-pip-dependencies
. env/bin/activate && python3 build-tools/docker/build.py --build=false --push --latest
Copy link
Contributor

Choose a reason for hiding this comment

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

IMO makefiles are worse than bash scripts. So, if we really need a non-python script on top of 'build.py', I'd say let's go with bash.
But I'm not sure we need one. I'd say that things like installing the appropriate python packages and managing virtual environments should be done manually by the developer, because different developers might have different preferences in this regard (personally, I wouldn't want to have the "env" directory inside the source tree). And if that part of the script is gone, it'll only contain a couple of calls to build.py, which probably doesn't require a wrapper script.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll put the dependencies in the readme


This document outlines the steps to build Docker images for the Mintlayer node daemon, wallet-cli, and node-gui.

Before building make sure you clone the repository and change directory in the root of the repository.
Copy link
Contributor

Choose a reason for hiding this comment

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

"change directory in" -> "change the current directory to"?


The `-v` option is used to mount a local directory (in this case `~/.mintlayer`) as a volume in the Docker container.
The `--user` option is used to specify the user that will write the `~/.mintlayer` directory.
NOTE: this wont work on windows hosts.
Copy link
Contributor

Choose a reason for hiding this comment

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

"wont" -> "won't"

```

The `-v` option is used to mount a local directory (in this case `~/.mintlayer`) as a volume in the Docker container.
The `--user` option is used to specify the user that will write the `~/.mintlayer` directory.
Copy link
Contributor

Choose a reason for hiding this comment

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

"will write the" -> "will write to the"?

Comment on lines 20 to 22
return version

def build_docker_image(dockerfile_path, image_name, version):
Copy link
Contributor

Choose a reason for hiding this comment

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

A nitpick: according to PEP8, top-level function definitions should be separated by 2 blank lines.

Comment on lines 27 to 33
process = subprocess.Popen(command, shell=True)
output, error = process.communicate()

if error:
print(f"Error occurred: {error}")
else:
print(f"Built {image_name}:{version} successfully.")
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't we stop the script if docker build fails? (i.e. why not just use check_call here like in other places?)


COPY . .

ARG NUM_JOBS=1
Copy link
Contributor

Choose a reason for hiding this comment

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

At this moment it's impossible to specify this value when using build.py. I'd be nice if the latter had an additional parameter for this.

@erubboli erubboli merged commit 78093bd into mintlayer:master Aug 8, 2023
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.

4 participants