Skip to content

Commit

Permalink
Update project configuration and add new files
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastian-quintero committed Feb 2, 2024
1 parent 93bf3cf commit 38ad286
Show file tree
Hide file tree
Showing 9 changed files with 225 additions and 164 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -162,3 +162,6 @@ cython_debug/
# Go stuff
go.work
go.work.sum

# VSCode stuff
.vscode/
8 changes: 4 additions & 4 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Options for analysis running. Details: https://golangci-lint.run/usage/configuration/#run-configuration
run:
timeout: 5m
go: "1.21"
go: "1.19"

# Configures linters. Details: https://golangci-lint.run/usage/linters
linters-settings:
Expand All @@ -17,11 +17,11 @@ linters-settings:
min-complexity: 45
# Set correct go version.
gosimple:
go: "1.21"
go: "1.19"
staticcheck:
go: "1.21"
go: "1.19"
stylecheck:
go: "1.21"
go: "1.19"
# Check case of struct tags
tagliatelle:
case:
Expand Down
23 changes: 23 additions & 0 deletions .nextmv/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Nextmv Workflows

This directory contains functionality for managing community apps.

## Requirements

- For Python scripts please install the packages in `requirements.txt`:

```bash
pip install -r requirements.txt
```

## Use

- To update one or more apps. Standing in the `./nextmv` directory, run:

```bash
python update_apps.py \
-a app1=version1,app2=version2 \
-b BUCKET \
-f FOLDER \
-m MANIFEST_FILE
```
File renamed without changes.
195 changes: 195 additions & 0 deletions .nextmv/update_apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
"""
This script updates one or more applications by:
1. Updating the version.
2. Updating the SDK version (if the app is written in Go).
3. Updating the manifest file and uploading it.
Execute from the ./nextmv directory:
```bash
python update_apps.py \
-a app1=version1,app2=version2 \
-b BUCKET \
-f FOLDER \
-m MANIFEST_FILE
```
"""

import argparse
import copy
import os
import subprocess
from typing import Any

import yaml
from boto3 import client as s3Client

parser = argparse.ArgumentParser(description="Update community apps in the Marketplace.")
parser.add_argument(
"--apps",
"-a",
type=str,
help="Apps to release, with the version. Example: knapsack-gosdk=v1.0.0,knapsack-pyomo=v1.0.0",
required=True,
)
parser.add_argument(
"--bucket",
"-b",
type=str,
help="S3 bucket.",
required=True,
)
parser.add_argument(
"--folder",
"-f",
type=str,
help="S3 bucket folder.",
required=True,
)
parser.add_argument(
"--manifest",
"-m",
type=str,
help="Manifest file.",
required=True,
)
args = parser.parse_args()


def main():
"""
Entry point for the script.
"""

apps = [
{
"name": app.split("=")[0],
"version": app.split("=")[1],
}
for app in args.apps.split(",")
]
apps.sort(key=lambda x: x["name"])
client = s3Client("s3")

manifest = get_manifest(
client=client,
bucket=args.bucket,
folder=args.folder,
manifest_file=args.manifest,
)
workflow_configuration = read_yaml(
filepath=os.path.join(os.getcwd(), "workflow-configuration.yml"),
)
for app in apps:
if "v" not in app["version"]:
app["version"] = f"v{app['version']}"

update_app(
name=app["name"],
version=app["version"],
workflow_configuration=workflow_configuration,
)
manifest = update_manifest(manifest, app)

upload_manifest(
client=client,
bucket=args.bucket,
folder=args.folder,
manifest_file=args.manifest,
manifest=manifest,
)


def update_app(name: str, version: str, workflow_configuration: dict[str, Any]):
"""Updates the app with the new version."""

workflow_info = {}
for app in workflow_configuration["apps"]:
if app["name"] == name:
workflow_info = app
break

with open(os.path.join(os.getcwd(), "..", name, "VERSION"), "w") as f:
f.write(version + "\n")

if workflow_info["type"] == "go":
sdk_version = workflow_info["sdk_version"]
if "v" not in sdk_version:
sdk_version = f"v{sdk_version}"

_ = subprocess.run(
["go", "get", f"github.com/nextmv-io/sdk@{sdk_version}"],
capture_output=True,
text=True,
check=True,
cwd=os.path.join("..", name),
)
_ = subprocess.run(
["go", "mod", "tidy"],
capture_output=True,
text=True,
check=True,
cwd=os.path.join("..", name),
)


def get_manifest(
client: s3Client,
bucket: str,
folder: str,
manifest_file: str,
) -> dict[str, Any]:
"""Returns the manifest from the S3 bucket."""

result = client.get_object(Bucket=bucket, Key=f"{folder}/{manifest_file}")
return yaml.safe_load(result["Body"].read())


def upload_manifest(
client: s3Client,
bucket: str,
folder: str,
manifest_file: str,
manifest: dict[str, Any],
):
"""Uploads the manifest to the S3 bucket."""

class Dumper(yaml.Dumper):
"""Custom YAML dumper that does not use the default flow style."""

def increase_indent(self, flow=False, indentless=False):
return super().increase_indent(flow, False)

client.put_object(
Bucket=bucket,
Key=f"{folder}/{manifest_file}",
Body=yaml.dump(manifest, Dumper=Dumper, default_flow_style=False),
)


def update_manifest(
old: dict[str, Any],
app: dict[str, Any],
) -> dict[str, Any]:
"""Updates the manifest with the new apps."""

new = copy.deepcopy(old)
for manifest_app in new["apps"]:
if manifest_app["name"] == app["name"]:
manifest_app["latest"] = app["version"]
manifest_app["versions"].append(app["version"])
break

return new


def read_yaml(filepath: str) -> dict[str, Any]:
"""Returns the YAML file in the path."""

with open(filepath) as f:
return yaml.safe_load(f)


if __name__ == "__main__":
main()
File renamed without changes.
1 change: 0 additions & 1 deletion VERSION

This file was deleted.

55 changes: 0 additions & 55 deletions scripts/update_app.sh

This file was deleted.

Loading

0 comments on commit 38ad286

Please sign in to comment.