Skip to content

Commit

Permalink
chore(build.py): add cli flag to use podman instead of docker (#379)
Browse files Browse the repository at this point in the history
podman's cli is arg-compatible with docker, at least for building
images. We can allow users to specify an alternate build engine.

* use flag instead of env variable
* readme
  • Loading branch information
bblancha authored Feb 6, 2024
1 parent 07805b8 commit 4f18d1c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ This will result in docker image called `octobot:latest` that you can deploy as
* Make sure that whatever path you map `/data` to is a persistent location since this is where configuration is stored.
* Create a `config.toml` file in this location before deploying (see below).

Using podman? use `build.py --use-podman`

### Configuration

There is one main config file to know about. Hopefully this examples will be sufficiently explanatory:
Expand Down
30 changes: 22 additions & 8 deletions build.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,25 @@
#!/usr/bin/env python3

import argparse
import os
import re
import shutil
import subprocess

parser = argparse.ArgumentParser(description='Build Octobot and package in a container')
parser.add_argument(
'--use-podman',
action='store_true',
help='Use podman to build container instead of docker',
)

args = parser.parse_args()
engine = 'docker'
if args.use_podman:
engine = 'podman'

is_travis = os.environ.get('TRAVIS') is not None

class task:
def __init__(self, title):
self.title = title
Expand Down Expand Up @@ -35,17 +49,17 @@ def run(cmd, ignore_fail=False, quiet=False):
os.makedirs(docker_out)

with task("Dockerfile.build"):
run("docker build . -f Dockerfile.build -t octobot:build")
run("{} build . -f Dockerfile.build -t octobot:build".format(engine))
with task("extract_files"):
run("docker rm -f extract", ignore_fail=True, quiet=True)
run("docker create --name extract octobot:build")
run("docker cp extract:/usr/src/app/target/release/octobot {}".format(docker_out))
run("docker cp extract:/usr/src/app/target/release/octobot-passwd {}".format(docker_out))
run("docker cp extract:/usr/src/app/target/release/octobot-ask-pass {}".format(docker_out))
run("docker rm -f extract")
run("{} rm -f extract".format(engine), ignore_fail=True, quiet=True)
run("{} create --name extract octobot:build".format(engine))
run("{} cp extract:/usr/src/app/target/release/octobot {}".format(engine, docker_out))
run("{} cp extract:/usr/src/app/target/release/octobot-passwd {}".format(engine, docker_out))
run("{} cp extract:/usr/src/app/target/release/octobot-ask-pass {}".format(engine, docker_out))
run("{} rm -f extract".format(engine))
# write out the version file
commit_hash = subprocess.check_output(['git', 'rev-parse', '--short', 'HEAD'])
with open(os.path.join(docker_out, 'version'), 'wb') as f:
f.write(commit_hash)
with task("Dockerfile"):
run("docker build . -t octobot:latest")
run("{} build . -t octobot:latest".format(engine))

0 comments on commit 4f18d1c

Please sign in to comment.