|
1 |
| -docker pull gridappsd/gridappsd_base:master |
| 1 | +#!/usr/bin/env python3 |
2 | 2 |
|
3 |
| -./gradlew clean |
4 |
| -rm -rf gov.pnnl.goss/gridappsd/generated |
5 |
| -./gradlew export |
| 3 | +""" |
| 4 | +Script for building the gridappsd container. |
6 | 5 |
|
7 |
| -docker build --no-cache --network=host -t gridappsd:local . |
| 6 | +This script pulls the gridappsd_base docker image, cleans the project, exports the project, and builds the gridappsd container. |
| 7 | +
|
| 8 | +Usage: |
| 9 | + python build-gridappsd-container <base_version> [--output_version <output_version>] |
| 10 | +
|
| 11 | +Arguments: |
| 12 | + base_version (str): The version of the gridappsd_base docker image. |
| 13 | + output_version (str, optional): The output tag version for local development. Default is "local". |
| 14 | +
|
| 15 | +Example: |
| 16 | + python build-gridappsd-container.py 2.3.0 --output_version 2.3.1 |
| 17 | +
|
| 18 | +""" |
| 19 | + |
| 20 | +import argparse |
| 21 | +import subprocess |
| 22 | +import shutil |
| 23 | + |
| 24 | + |
| 25 | +def execute(cmd: str | list[str]): |
| 26 | + """ |
| 27 | + Executes a command in the shell and prints the output. |
| 28 | +
|
| 29 | + Args: |
| 30 | + cmd (str | list[str]): The command to execute. If a string, it will be split into a list of arguments. |
| 31 | +
|
| 32 | + Raises: |
| 33 | + subprocess.CalledProcessError: If the command returns a non-zero exit code. |
| 34 | +
|
| 35 | + """ |
| 36 | + if isinstance(cmd, str): |
| 37 | + cmd = cmd.split(" ") |
| 38 | + |
| 39 | + with subprocess.Popen(cmd, stdout=subprocess.PIPE, universal_newlines=True) as p: |
| 40 | + for line in iter(p.stdout.readline, ""): |
| 41 | + if line.strip(): |
| 42 | + print(line.strip()) |
| 43 | + |
| 44 | + p.wait() |
| 45 | + if p.returncode: |
| 46 | + raise subprocess.CalledProcessError(p.returncode, cmd=" ".join(cmd)) |
| 47 | + |
| 48 | + |
| 49 | + |
| 50 | +if __name__ == '__main__': |
| 51 | + |
| 52 | + parser = argparse.ArgumentParser() |
| 53 | + |
| 54 | + parser.add_argument("base_version", |
| 55 | + help="The gridappsd_base docker image version") |
| 56 | + parser.add_argument("--output_version", default="local", |
| 57 | + help="The output tag version for local development") |
| 58 | + |
| 59 | + opts = parser.parse_args() |
| 60 | + |
| 61 | + base_version = opts.base_version |
| 62 | + |
| 63 | + execute(f"docker pull gridappsd/gridappsd_base:{opts.base_version}") |
| 64 | + execute("./gradlew clean") |
| 65 | + shutil.rmtree("gov.pnnl.goss/gridappsd/generated", ignore_errors=True) |
| 66 | + execute("./gradlew export") |
| 67 | + execute(f"docker build --build-arg GRIDAPPSD_BASE_VERSION=:{opts.base_version} --no-cache --network=host -t gridappsd:{opts.output_version} .") |
0 commit comments