Skip to content

Commit

Permalink
Revise versioning and tagging.
Browse files Browse the repository at this point in the history
  • Loading branch information
csadorf committed Aug 18, 2022
1 parent 9b865d8 commit 735fe9a
Show file tree
Hide file tree
Showing 10 changed files with 167 additions and 27 deletions.
14 changes: 13 additions & 1 deletion .github/workflows/build_and_test_on_pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,25 +33,37 @@ jobs:
uses: docker/setup-buildx-action@v2
with:
driver-opts: network=host
- name: Obtain Docker build args
id: meta_extra
run: |
echo "::set-output name=build_args::$(./build.py docker-build-args --github-actions)"
- name: Build aiida image
uses: docker/build-push-action@v3
with:
# TODO: rename to stack/base
context: stack/aiida
tags: localhost:5000/aiidalab/aiida:latest
build-args: |
${{ steps.meta_extra.outputs.build_args }}
push: true
- name: Build aiidalab image
uses: docker/build-push-action@v3
with:
# TODO: rename to stack/lab
context: stack/aiidalab
tags: aiidalab/aiidalab:latest
load: true
build-args: |
BASE_IMAGE=localhost:5000/aiidalab/aiida:latest
${{ steps.meta_extra.outputs.build_args }}
BASE_IMAGE=localhost:5000/aiidalab/aiida
VERSION=latest
- uses: actions/setup-python@v4
with:
python-version: '3.10'
cache: pip # caching pip dependencies
- run: pip install -r tests/requirements.txt
- name: Run tests
env:
AIIDALAB_IMAGE: 'aiidalab/aiidalab:latest'
run: |
pytest -v
44 changes: 33 additions & 11 deletions .github/workflows/release_image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ on:
branches:
- master
- develop
- refactor-into-stack # DEBUG
tags:
- v[0-9]+.[0-9]+.[0-9]+*

Expand All @@ -20,6 +21,13 @@ jobs:

steps:
- uses: actions/checkout@v2
- name: Install Conda environment from environment.yml
uses: mamba-org/provision-with-micromamba@v12
- name: Docker meta exta
id: meta_extra
run: |
echo "::set-output name=tags::$(./build.py tags --github-actions)"
echo "::set-output name=build_args::$(./build.py docker-build-args --github-actions)"
- name: Docker meta
id: meta
uses: docker/metadata-action@v4
Expand All @@ -28,19 +36,33 @@ jobs:
tags: |
type=ref,event=branch
type=pep440,pattern={{version}}
${{ steps.meta_extra.outputs.tags }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Login to DockerHub
uses: docker/login-action@v1
uses: docker/setup-buildx-action@v2
# - name: Login to DockerHub
# uses: docker/login-action@v1
# with:
# username: ${{ secrets.DOCKER_USERNAME }}
# password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build and push aiida image
uses: docker/build-push-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build and push
id: docker_build
uses: docker/build-push-action@v2
with:
push: true
context: stack/aiida
# push: true
tags: ${{ steps.meta.outputs.tags }}
platforms: linux/amd64, linux/arm64
build-args: |
${{ steps.meta_extra.outputs.build_args }}
BASE_IMAGE=localhost:5000/aiidalab/aiida
VERSION=latest
- name: Build and push aiidalab image
uses: docker/build-push-action@v3
with:
context: stack/aiidalab
# push: true
tags: ${{ steps.meta.outputs.tags }}
platforms: linux/amd64, linux/arm64
build-args: |
${{ steps.meta_extra.outputs.build_args }}
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ repos:
rev: 0.2.2
hooks:
- id: yamlfmt
args: [--preserve-quotes]

- repo: https://github.com/sirosen/check-jsonschema
rev: 0.17.0
Expand Down
63 changes: 63 additions & 0 deletions build.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/usr/bin/env python
from pathlib import Path

import click
from yaml import SafeLoader, load

BUILD_CONFIG = load(Path("build.yml").read_text(), Loader=SafeLoader)


def get_organization():
return BUILD_CONFIG["organization"]


def get_version():
return BUILD_CONFIG["version"]


def get_tags():
yield BUILD_CONFIG["version"] # The version of the stack.
# The versions of dependencies:
for name, version in BUILD_CONFIG["versions"].items():
yield f"{name}-{version}"


def get_docker_build_args():
yield f"VERSION={BUILD_CONFIG['version']}"
for name, version in BUILD_CONFIG["versions"].items():
yield f"{name.upper()}_VERSION={version}"


@click.group()
def cli():
pass


@cli.command()
@click.option(
"--github-actions",
is_flag=True,
help="Output tags in a format convenient for GitHub actions.",
)
def tags(github_actions):
if github_actions:
click.echo(r"%0A".join(get_tags()))
else:
click.echo("\n".join(get_tags()))


@cli.command()
@click.option(
"--github-actions",
is_flag=True,
help="Output tags in a format convenient for GitHub actions.",
)
def docker_build_args(github_actions):
if github_actions:
click.echo(r"%0A".join(get_docker_build_args()))
else:
click.echo(" ".join(f"--build-arg {arg}" for arg in get_docker_build_args()))


if __name__ == "__main__":
cli()
6 changes: 6 additions & 0 deletions build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
organization: aiidalab
version: '2022.1001'
versions:
python: '3.9.4'
aiida: '2.0.0'
21 changes: 21 additions & 0 deletions bumpver.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[bumpver]
current_version = "2022.1001"
version_pattern = "YYYY.BUILD[-TAG]"
commit_message = "Bump version {old_version} -> {new_version}."
commit = true
tag = false
push = false

[bumpver.file_patterns]
"build.yml" = [
"version: '{version}'"
]
"bumpver.toml" = [
'current_version = "{version}"',
]
"docker-compose.yml" = [
"aiidalab/aiidalab:{version}"
]
"stack/aiidalab/Dockerfile" = [
'ARG VERSION={version}'
]
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ services:
- aiida-rmq-data:/var/lib/rabbitmq/

aiidalab:
image: aiidalab/aiidalab:latest
image: ${AIIDALAB_IMAGE:-aiidalab/aiidalab:2022.1001}
environment:
RMQHOST: messaging
TZ: Europe/Zurich
Expand Down
23 changes: 16 additions & 7 deletions dodo.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,33 @@
from pathlib import Path

ORG = "aiidalab"
VER = "latest"
from build import get_docker_build_args, get_organization, get_tags, get_version

DOIT_CONFIG = {"default_tasks": ["build"]}


def task_build():
"""Build all docker images."""

contexts = [p.parent for p in Path("stack").glob("*/Dockerfile")]
contexts = [p.parent for p in sorted(Path("stack").glob("*/Dockerfile"))]
organization = get_organization()
version = get_version() # The version of the stack.

for context in contexts:
image = f"{ORG}/{context.name}:{VER}"
image = f"{organization}/{context.name}"

deps = [p for p in context.glob("**/*") if p.is_file()]
build_action = ["docker", "build"]
build_action.extend([f"-t {image}:{tag}" for tag in get_tags()])
build_action.extend(f"--build-arg {arg}" for arg in get_docker_build_args())
build_action.append(str(context))
build_action = " ".join(build_action)

deps = ["build.yml", "build.py"] + [
p for p in context.glob("**/*") if p.is_file()
]

yield {
"name": image,
"actions": [f"docker build -t {image} {context}"],
"name": f"{image}:{version}",
"actions": [build_action],
"file_dep": deps,
"verbosity": 2,
}
Expand Down
14 changes: 10 additions & 4 deletions stack/aiida/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,26 +1,32 @@
FROM jupyter/minimal-notebook:python-3.9.12
ARG PYTHON_VERSION=3.9.12
FROM jupyter/minimal-notebook:python-${PYTHON_VERSION}

LABEL maintainer="AiiDAlab Team <aiidalab@materialscloud.org>"

ARG AIIDA_VERSION=2.0.1

USER root
WORKDIR /opt/

# Install the shared requirements.
COPY requirements.txt .
RUN mamba install --yes \
--file requirements.txt && \
mamba clean -all -f -y && \
aiida-core=${AIIDA_VERSION} \
--file requirements.txt \
&& mamba clean --all -f -y && \
fix-permissions "${CONDA_DIR}" && \
fix-permissions "/home/${NB_USER}"


# Pin shared requirements in the base environemnt.
RUN cat requirements.txt | xargs -I{} conda config --system --add pinned_packages {}

# Configure pip to use requirements file as constraints file.
ENV PIP_CONSTRAINT=/opt/requirements.txt

# Enable verdi autocompletion.
RUN echo 'eval "$(_VERDI_COMPLETE=source verdi)"' >> "${CONDA_DIR}/etc/conda/activate.d/activate_aiida_autocompletion.sh" && \
RUN mkdir -p "${CONDA_DIR}/etc/conda/activate.d" && \
echo 'eval "$(_VERDI_COMPLETE=source verdi)"' >> "${CONDA_DIR}/etc/conda/activate.d/activate_aiida_autocompletion.sh" && \
chmod +x "${CONDA_DIR}/etc/conda/activate.d/activate_aiida_autocompletion.sh" && \
fix-permissions "${CONDA_DIR}"

Expand Down
6 changes: 3 additions & 3 deletions stack/aiidalab/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# TODO: use proper base tag
ARG BASE_IMAGE=aiidalab/aiida:latest
FROM ${BASE_IMAGE}
ARG BASE_IMAGE=aiidalab/aiida
ARG VERSION=2022.1001
FROM ${BASE_IMAGE}:${VERSION}

LABEL maintainer="AiiDAlab Team <aiidalab@materialscloud.org>"

Expand Down

0 comments on commit 735fe9a

Please sign in to comment.