Skip to content

Commit a7418df

Browse files
committed
Trying some stuff
1 parent 7da8d7e commit a7418df

File tree

2 files changed

+107
-9
lines changed

2 files changed

+107
-9
lines changed

github-ci/src/biocontainersci/ci.py

Lines changed: 99 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,25 +24,25 @@ def __init__(self, config):
2424
self.docker_client = docker.DockerClient(base_url='unix://var/run/docker.sock', timeout=600)
2525
# urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
2626

27-
def name(self, f):
27+
def name(self, f, is_arm=False):
2828
'''
2929
Container name, not local version suffix
3030
'''
31-
return 'biocontainers/' + f['container'] + ':' + f['version']
31+
return 'biocontainers/' + f['container'] + ':' + f['version'] + "_arm" if is_arm else ""
3232

33-
def dockerhub_name(self, f):
33+
def dockerhub_name(self, f, is_arm=False):
3434
'''
3535
Docker registry name
3636
'''
37-
return 'biocontainers/' + f['container'] + ':' + f['tag']
37+
return 'biocontainers/' + f['container'] + ':' + f['tag'] + "_arm" if is_arm else ""
3838

39-
def local_name(self, f):
39+
def local_name(self, f, is_arm=False):
4040
'''
4141
Local registry name
4242
'''
4343
if not self.config['registry']['url']:
4444
return None
45-
return self.config['registry']['url'] + '/biocontainers/' + f['container'] + ':' + f['tag']
45+
return self.config['registry']['url'] + '/biocontainers/' + f['container'] + ':' + f['tag'] + "_arm" if is_arm else ""
4646

4747
def run_test(self, f: dict, test: str):
4848
'''
@@ -213,6 +213,99 @@ def singularity(self, f):
213213
def workdir(self):
214214
return os.environ.get('GITHUB_WORKSPACE', os.getcwd())
215215

216+
'''
217+
Execute minimal CI workflow for arm build
218+
* build container
219+
'''
220+
def workflow_arm(self, f):
221+
base_container_name = self.name(f, is_arm=True)
222+
logging.info('[ci][build]ARM ' + base_container_name)
223+
224+
build_logs = []
225+
try:
226+
(docker_image, build_logs) = self.docker_client.images.build(
227+
path=os.path.join(self.workdir(), f['container'], f['version']),
228+
tag=base_container_name,
229+
squash=False,
230+
nocache=True,
231+
rm=True,
232+
platform="linux/arm64"
233+
)
234+
self.docker_logs(build_logs)
235+
except Exception as e:
236+
self.docker_logs(build_logs)
237+
logging.exception('[ci][build]ARM error ' + str(e))
238+
return False
239+
240+
status = False
241+
try:
242+
labels = docker_image.labels
243+
logging.info('[ci][build][labels] ' + json.dumps(labels))
244+
status = self.check_labels(f, labels)
245+
if not status:
246+
return False
247+
logging.info('[ci][build] ' + json.dumps(f))
248+
249+
# tag for docker and local registry
250+
logging.info("tag for dockerhub")
251+
self.docker_client.images.build(
252+
path=os.path.join(self.workdir(), f['container'], f['version']),
253+
tag=self.dockerhub_name(f, is_arm=True),
254+
squash=False,
255+
nocache=False,
256+
rm=True,
257+
platform="linux/arm64"
258+
259+
)
260+
if self.local_name(f):
261+
logging.info("tag for local registry")
262+
self.docker_client.images.build(
263+
path=os.path.join(self.workdir(), f['container'], f['version']),
264+
tag=self.local_name(f, is_arm=True),
265+
squash=False,
266+
nocache=False,
267+
rm=True,
268+
platform="linux/arm64"
269+
)
270+
271+
# push
272+
if self.config['dockerhub']['username']:
273+
self.docker_push(self.dockerhub_name(f, is_arm=True), auth_config={
274+
'username': self.config['dockerhub']['username'],
275+
'password': self.config['dockerhub']['password']
276+
})
277+
else:
278+
logging.info('no dockerhub credentials, skipping')
279+
if self.local_name(f):
280+
self.docker_push(self.local_name(f, is_arm=True))
281+
else:
282+
logging.info('no local registry, skipping')
283+
284+
status = True
285+
except Exception as e:
286+
logging.exception('[ci][workflow] error: ' + str(e))
287+
status = False
288+
289+
try:
290+
self.docker_client.images.remove(image=self.name(f, is_arm=True), force=True)
291+
except Exception:
292+
pass
293+
try:
294+
self.docker_client.images.remove(image=self.dockerhub_name(f, is_arm=True), force=True)
295+
except Exception:
296+
pass
297+
try:
298+
self.docker_client.images.remove(image=self.local_name(f, is_arm=True), force=True)
299+
except Exception:
300+
pass
301+
302+
logging.info('Docker images prune')
303+
self.docker_client.images.prune()
304+
305+
logging.info('Docker containers prune')
306+
self.docker_client.containers.prune()
307+
return status
308+
216309
'''
217310
Execute CI workflow
218311

github-ci/src/biocontainersci/main.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,14 @@ def github_pull_request_files(config):
5454
if '.github' in pull_file['filename']:
5555
msg = 'Cannot modify github CI files....'
5656
logging.error(msg)
57-
send_github_pr_comment(config, msg)
57+
send_github_pr_comment(config, msg)
5858
raise BiocontainersException(msg)
5959
logging.info('[ci][github][pull request] ' + pull_file['filename'])
6060
filenames = pull_file['filename'].split('/')
6161
if len(filenames) < 2:
6262
msg = "You're trying to update a file not related to a container: " + str(pull_file['filename']) + ", this is forbidden"
6363
logging.error(msg)
64-
send_github_pr_comment(config, msg)
64+
send_github_pr_comment(config, msg)
6565
raise BiocontainersException(msg)
6666
container_path = '/'.join([filenames[0], filenames[1]])
6767
if container_path not in containers:
@@ -101,7 +101,12 @@ def github(config):
101101

102102
def bioworkflow(config, f):
103103
ci = CI(config)
104-
return ci.workflow(f)
104+
amd_build = ci.workflow(f)
105+
if amd_build:
106+
arm_build = ci.workflow_arm(f)
107+
if arm_build:
108+
ci.build_manifest(f)
109+
return amd_build
105110

106111
@click.command()
107112
@click.option('--file', help='Dockerfile')

0 commit comments

Comments
 (0)