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

Download and build podman-compose using docker/podman locally #1043

Merged
merged 2 commits into from
Nov 3, 2024

Conversation

iruzo
Copy link
Contributor

@iruzo iruzo commented Sep 21, 2024

Reason for this PR

As a user of Fedora Silverblue I found that the easiest ways to install podman-compose are:

  • Open a toolbox/distrobox container, install there the python dependencies, use pyinstaller, generate a podman-compose binary and move it outside of the container to use it.
  • Create a virtual env, install dependencies and use pyinstaller to compile it.
  • Install Podman Desktop and let it install and manage podman-compose.
  • [Not actually podman-compose] Manually set podman.socket and downloading docker-compose.

I just wanted to execute a single command and obtain a binary I can save on my home directory without modifying anything outside my $HOME.

Changes

  • Adds Dockerfile that compiles podman-compose and let the binary on /result.
  • Adds a script to generate the binary and drop it on the current directory.
  • Adds script to simplify this process so people can just "download" the binary by executing a single shell command.

Usage

sh -c "$(curl -sSL https://raw.githubusercontent.com/containers/podman-compose/main/scripts/download_podman-compose.sh)"

Using this approach, everything happens within the build steps of the Dockerfile, so no dependencies or temporary files should be left on your system.

Thanks in advance. Any suggestions are welcome.

@p12tic
Copy link
Collaborator

p12tic commented Sep 26, 2024

Thanks for the PR. It will take some time to review it. Ideally I would like to have this as part of release process so that the executables are added to release artifacts.

@iruzo
Copy link
Contributor Author

iruzo commented Oct 17, 2024

Hey @p12tic,

Thank you for being so fast to reply to my PR.
I just added in a commit a release.yml that add the binary to the next release (in case GITHUB_TOKEN is enabled in the repo).

Please, take your time to review the PR, there is no need to rush, thanks for just taking a look at it 😃

README.md Outdated
### Generate binary using docker/podman locally
This script will download the repo, generate the binary using [this Dockerfile](https://github.com/containers/podman-compose/blob/main/Dockerfile.md) and let the binary in the directory where you called this script.
```bash
sh -c "$(curl -sSL https://raw.githubusercontent.com/containers/podman-compose/main/scripts/download_podman-compose.sh)"
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this should better named as build_podman-compose.sh, because we're not just downloading. Also add a mention that the script will call sudo in case of docker-based build because this is rather sensitive to some people.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmmm, yeah, you are probably right, but since there is already a script called generate_binary_using_dockerfile.sh, having one with "build" could lead to confusion.

What do you think about naming it "build_and_download_podman-compose.sh" ?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Makes sense. But maybe download_and_build_podman-compose.sh ? So that reading left to right the sequence of events is correct.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree with you. I just pushed the changes 😄

CONTAINER_TOOL=$(find_container_tool)

# Find the directory containing the dockerfile by traversing up the directory tree
find_dockerfile_dir() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it would be simpler to get the path to the script using $(dirname "$0") and then take ../Dockerfile. Traversing whole directory tree is not needed.

Copy link
Contributor Author

@iruzo iruzo Oct 21, 2024

Choose a reason for hiding this comment

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

The reason for this is to be able to call the script from wherever you want without being worried to break the podman build command.
Thanks to this I can call the script from the download one while being outside the repository dir.

Also, if for some reason you want to move the scripts to other dir, you can be sure that they will not break.

Copy link
Collaborator

Choose a reason for hiding this comment

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

My suggestion would still achieve this, unless I'm missing something.

$(dirname "$0") would return the path to the directory this script is in. Because the repository structure is /Dockerfile and /scripts/generate_binary_using_dockerfile.sh, then $(dirname "$0")/../Dockerfile should always point to the Dockerfile regardless of where this script is called from.

Am I missing something why this wouldn't work?

I agree that moving the scripts somewhere could be a problem, but I don't think we will move the scripts in the foreseeable future.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If you use $(dirname "$0")/../Dockerfile, this will work as long as your keep the script in a subdir at the same level as it is right now.

e.g. If you change the script to /root/scripts/docker-scripts/generate_binary_using_dockerfile.sh, the script will break.

But yeah, you are right that it should still work if you call it from any other directory. So, if you are fine with keeping the script always under /scripts, I can make the change knowing that it will never break.

Since I didn't know if you will ever move the script to any other dir, I decided to do the find on the directory tree. Now that you are suggesting this, I imagine the directory structure will always be the same, so I'm going to make the change and ping you once done 😄 .

SELINUX=$(check_selinux)

# Build binary
$CONTAINER_TOOL image rm podman-compose
Copy link
Collaborator

Choose a reason for hiding this comment

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

Use something like build-podman-compose so that it has less chances to conflict with container names already on the system.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are right!, I just pushed the changes.

@p12tic
Copy link
Collaborator

p12tic commented Oct 19, 2024

I actually forgot about this PR because I somehow thought that I'm waiting for something from you. Thanks for the ping. I have reviewed the PR now, looks good except several comments that should be simple to address.

@iruzo
Copy link
Contributor Author

iruzo commented Oct 23, 2024

@p12tic
I just pushed the change to stop doing a recursive search on the directory tree.
Also, I noticed that docker build does not have a -v parameter (oopsie, since I use podman, I didn't notice until I try it today), I changed the script so it would also work with docker.

@p12tic
Copy link
Collaborator

p12tic commented Nov 3, 2024

Thanks a lot for fixes, they look great.

@p12tic
Copy link
Collaborator

p12tic commented Nov 3, 2024

I rebased to squash fixup commits into the commit they are fixing.

@p12tic p12tic merged commit 4ae6ccb into containers:main Nov 3, 2024
7 checks passed
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.

2 participants