Skip to content

Commit 054ba1c

Browse files
committed
Add flatpak metadata
- Change how `docker-command` is parsed to allow for command line options. - Add CI test build Signed-off-by: Nicolas Bock <[email protected]>
1 parent 81f7029 commit 054ba1c

10 files changed

+124
-28
lines changed

Diff for: .github/workflows/build.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: build
1+
name: Build and Test ebuildtester
22

33
on:
44
pull_request:

Diff for: .github/workflows/flatpak.yaml

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Build flatpack package
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
push:
8+
branches:
9+
- main
10+
11+
jobs:
12+
13+
build:
14+
runs-on: ubuntu-latest
15+
name: Build flatpak
16+
steps:
17+
18+
- name: Check out sources
19+
uses: actions/checkout@v2
20+
21+
- name: Set up flatpak build tools
22+
run: |
23+
set -e -u -x
24+
25+
sudo apt update
26+
sudo apt install flatpak flatpak-builder
27+
sudo flatpak remote-add --if-not-exists \
28+
flathub https://flathub.org/repo/flathub.flatpakrepo
29+
sudo flatpak install --assumeyes flathub \
30+
org.freedesktop.Platform//21.08 org.freedesktop.Sdk//21.08
31+
32+
- name: Build flatpak
33+
run: make flatpak

Diff for: .github/workflows/publish.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22

3-
name: Publish
3+
name: Publish PyPI Package
44

55
on:
66
release:

Diff for: .gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ build/
22
dist/
33
ebuildtester.egg-info/
44
*__pycache__*
5+
.vscode/

Diff for: Makefile

+3
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,6 @@ docs:
1313

1414
distclean:
1515
rm -rf dist/*
16+
17+
flatpak:
18+
flatpak-builder --force-clean build-dir org.nicolasbock.ebuildtester.yaml

Diff for: ebuildtester-wrapper.sh

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/bash
2+
3+
set -e -u
4+
5+
/app/usr/bin/ebuildtester --docker-command "flatpak-spawn --host docker" "$@"

Diff for: ebuildtester/docker.py

+27-26
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@
88

99

1010
class ExecuteFailure(Exception):
11+
"""Failure to execute command."""
1112
pass
1213

1314

1415
class Docker:
15-
16+
"""The Docker class."""
1617
def __init__(self, local_portage, overlay_dirs):
1718
"""Create a new container."""
1819

@@ -44,7 +45,7 @@ def execute(self, cmd):
4445
"""
4546

4647
options.log.info("%s %s" % (self.cid[:6], cmd))
47-
docker_cmd = [options.options.docker_command, "exec", "--interactive"]
48+
docker_cmd = options.options.docker_command + ["exec", "--interactive"]
4849
docker_cmd += [self.cid, "/bin/bash"]
4950
docker = subprocess.Popen(docker_cmd,
5051
stdout=subprocess.PIPE,
@@ -94,9 +95,9 @@ def shell(self):
9495
"""Run an interactive shell in container."""
9596

9697
options.log.info("running interactive shell in container")
97-
docker = subprocess.Popen([options.options.docker_command,
98-
"exec", "--tty", "--interactive",
99-
self.cid, "/bin/bash"])
98+
docker = subprocess.Popen(options.options.docker_command
99+
+ ["exec", "--tty", "--interactive",
100+
self.cid, "/bin/bash"])
100101
try:
101102
docker.wait()
102103
except KeyboardInterrupt:
@@ -112,12 +113,12 @@ def remove(self):
112113
"""Remove the docker container."""
113114

114115
options.log.info("stopping container")
115-
docker = subprocess.Popen([options.options.docker_command,
116-
"kill", self.cid])
116+
docker = subprocess.Popen(options.options.docker_command
117+
+ ["kill", self.cid])
117118
docker.wait()
118119
options.log.info("deleting container")
119-
docker = subprocess.Popen([options.options.docker_command,
120-
"rm", self.cid])
120+
docker = subprocess.Popen(options.options.docker_command
121+
+ ["rm", self.cid])
121122
docker.wait()
122123

123124
def _reader(self, proc, stream, name):
@@ -135,27 +136,27 @@ def _setup_container(self, docker_image):
135136
"""Setup the container."""
136137

137138
if options.options.pull:
138-
docker_args = [options.options.docker_command,
139-
"pull", docker_image]
139+
docker_args = options.options.docker_command \
140+
+ ["pull", docker_image]
140141
docker = subprocess.Popen(docker_args)
141142
docker.wait()
142143

143144
def _create_container(self, docker_image, local_portage, overlays):
144145
"""Create new container."""
145146

146-
docker_args = [
147-
options.options.docker_command, "create",
148-
"--tty",
149-
"--cap-add", "CAP_SYS_ADMIN",
150-
"--cap-add", "CAP_MKNOD",
151-
"--cap-add", "CAP_NET_ADMIN",
152-
# https://github.com/moby/moby/issues/16429
153-
"--security-opt", "apparmor:unconfined",
154-
"--device", "/dev/fuse",
155-
"--workdir", "/root",
156-
"--volume", "%s:/var/db/repos/gentoo" % local_portage,
157-
"--volume", "%s/distfiles:/var/cache/distfiles" % local_portage,
158-
"--volume", "%s/packages:/var/cache/binpkgs" % local_portage]
147+
docker_args = options.options.docker_command \
148+
+ ["create",
149+
"--tty",
150+
"--cap-add", "CAP_SYS_ADMIN",
151+
"--cap-add", "CAP_MKNOD",
152+
"--cap-add", "CAP_NET_ADMIN",
153+
# https://github.com/moby/moby/issues/16429
154+
"--security-opt", "apparmor:unconfined",
155+
"--device", "/dev/fuse",
156+
"--workdir", "/root",
157+
"--volume", "%s:/var/db/repos/gentoo" % local_portage,
158+
"--volume", "%s/distfiles:/var/cache/distfiles" % local_portage,
159+
"--volume", "%s/packages:/var/cache/binpkgs" % local_portage]
159160

160161
if options.options.storage_opt:
161162
for s in options.options.storage_opt:
@@ -182,8 +183,8 @@ def _create_container(self, docker_image, local_portage, overlays):
182183
def _start_container(self):
183184
"""Start the container."""
184185

185-
docker_args = [options.options.docker_command,
186-
"start", "%s" % self.cid]
186+
docker_args = options.options.docker_command \
187+
+ ["start", "%s" % self.cid]
187188
docker = subprocess.Popen(docker_args, stdout=subprocess.PIPE)
188189
docker.wait()
189190
if docker.returncode != 0:

Diff for: ebuildtester/parse.py

+4
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,10 @@ def parse_commandline(args):
150150
if not options.docker_command:
151151
options.docker_command = os.getenv('DOCKER_COMMAND', default='docker')
152152

153+
# Convert docker command into list so that `subprocess` can run the command
154+
# and add command line options if they are present.
155+
options.docker_command = options.docker_command.split()
156+
153157
if options.show_options:
154158
print(options)
155159

Diff for: org.nicolasbock.ebuildtester.yaml

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
app-id: org.nicolasbock.ebuildtester
2+
runtime: org.freedesktop.Platform
3+
runtime-version: '21.08'
4+
sdk: org.freedesktop.Sdk
5+
command: ebuildtester
6+
finish-args:
7+
- --talk-name=org.freedesktop.Flatpak
8+
modules:
9+
- python3-modules.json
10+
- name: ebuildtester
11+
buildsystem: simple
12+
build-commands:
13+
- pip3 install --prefix /app --verbose .
14+
- python setup.py install --prefix /app --verbose
15+
- mkdir --parents /app/usr/bin
16+
- mv --verbose /app/bin/ebuildtester /app/usr/bin/ebuildtester
17+
- install --verbose -D ebuildtester-wrapper.sh /app/bin/ebuildtester
18+
sources:
19+
- type: dir
20+
path: .

Diff for: python3-modules.json

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"name": "python3-setuptools-scm",
3+
"buildsystem": "simple",
4+
"build-commands": [
5+
"pip3 install --verbose --exists-action=i --no-index --find-links=\"file://${PWD}\" --prefix=${FLATPAK_DEST} \"setuptools-scm\" --no-build-isolation"
6+
],
7+
"sources": [
8+
{
9+
"type": "file",
10+
"url": "https://files.pythonhosted.org/packages/97/75/10a9ebee3fd790d20926a90a2547f0bf78f371b2f13aa822c759680ca7b9/tomli-2.0.1-py3-none-any.whl",
11+
"sha256": "939de3e7a6161af0c887ef91b7d41a53e7c5a1ca976325f429cb46ea9bc30ecc"
12+
},
13+
{
14+
"type": "file",
15+
"url": "https://files.pythonhosted.org/packages/05/8e/8de486cbd03baba4deef4142bd643a3e7bbe954a784dc1bb17142572d127/packaging-21.3-py3-none-any.whl",
16+
"sha256": "ef103e05f519cdc783ae24ea4e2e0f508a9c99b2d4969652eed6a2e1ea5bd522"
17+
},
18+
{
19+
"type": "file",
20+
"url": "https://files.pythonhosted.org/packages/e3/e5/c28b544051340e63e0d507eb893c9513d3a300e5e9183e2990518acbfe36/setuptools_scm-6.4.2-py3-none-any.whl",
21+
"sha256": "acea13255093849de7ccb11af9e1fb8bde7067783450cee9ef7a93139bddf6d4"
22+
},
23+
{
24+
"type": "file",
25+
"url": "https://files.pythonhosted.org/packages/d9/41/d9cfb4410589805cd787f8a82cddd13142d9bf7449d12adf2d05a4a7d633/pyparsing-3.0.8-py3-none-any.whl",
26+
"sha256": "ef7b523f6356f763771559412c0d7134753f037822dad1b16945b7b846f7ad06"
27+
}
28+
]
29+
}

0 commit comments

Comments
 (0)