Skip to content

Commit

Permalink
Merge pull request #28 from nextmv-io/feature/fix-release
Browse files Browse the repository at this point in the history
Fix release workflow for Go type without plugins
  • Loading branch information
sebastian-quintero authored Mar 15, 2024
2 parents b7a2c52 + 25d3dab commit 3cf2d53
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 22 deletions.
3 changes: 3 additions & 0 deletions .nextmv/golden/knapsack-ampl/inputs/input.json.golden
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@
"value": 444
},
"run": {
"custom": {
"license_used": "demo"
},
"duration": 0.123
},
"schema": "v1"
Expand Down
1 change: 0 additions & 1 deletion .nextmv/golden/knapsack-ampl/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ func TestMain(m *testing.M) {
}

func TestGolden(t *testing.T) {
t.Skip("skipping until we have a fix for ample license on x64")
golden.FileTests(
t,
"inputs",
Expand Down
4 changes: 2 additions & 2 deletions .nextmv/update_apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,8 @@ def update_app(name: str, version: str):
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"]
sdk_version = workflow_info.get("sdk_version") or None
if workflow_info["type"] == "go" and sdk_version is not None:
if sdk_version != "latest" and "v" not in sdk_version:
sdk_version = f"v{sdk_version}"

Expand Down
1 change: 0 additions & 1 deletion .nextmv/workflow-configuration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ apps:
description: Solve a knapsack problem using Pyomo.
- name: nextroute
type: go
sdk_version: latest
app_id: nextroute
marketplace_app_id: nextroute
description: Solve a vehicle routing problem using Nextmv’s Nextroute.
Expand Down
7 changes: 4 additions & 3 deletions knapsack-ampl/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ The most important files created are `main.py`, `input.json`, and
* If you have an AMPL license, remove the `.template` extension and replace
the contents with your actual license key to be left with a file named
`ampl_license_uuid`. Modify the `app.yaml` file to include the
`ampl_license_uuid` in the files list.
`ampl_license_uuid` in the files list. Note: when running on Nextmv Cloud,
you should use a premium execution class to use your own AMPL license.
* If you are just testing and don’t have an AMPL license, you don’t need to
do anything, as this community app ships with a special license that allows
you to test AMPL with limits per AMPL's website.
do anything, as this community app ships with logic that allows you to test
AMPL with limits per AMPLs website.

Follow these steps to run locally.

Expand Down
55 changes: 40 additions & 15 deletions knapsack-ampl/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@

import argparse
import json
import os
import sys
import time
from platform import uname
from typing import Any

from amplpy import AMPL, ErrorHandler, OutputHandler, modules
Expand Down Expand Up @@ -99,14 +101,7 @@ def solve(input_data: dict[str, Any], duration: int, provider: str) -> dict[str,
start_time = time.time()

# Activate license.
modules.activate("nextmv")

# If you have an AMPL license, uncomment the following block.
# try:
# license = read_license_uuid()
# modules.activate(license)
# except Exception:
# log("Using default AMPL license for Nextmv")
license_used = activate_license()

# Defines the model.
ampl = AMPL()
Expand Down Expand Up @@ -179,6 +174,9 @@ def solve(input_data: dict[str, Any], duration: int, provider: str) -> dict[str,
},
"run": {
"duration": time.time() - start_time,
"custom": {
"license_used": license_used,
},
},
"schema": "v1",
}
Expand All @@ -189,6 +187,40 @@ def solve(input_data: dict[str, Any], duration: int, provider: str) -> dict[str,
}


def activate_license() -> str:
"""
Activates de AMPL license based on the use case for the app. If there is a
license configured in the file, and it is different from the template
message, it activates the license. Otherwise, use a special module if
running on Nextmv Cloud. No further action required for testing locally.
Returns:
str: The license that was activated: "license", "nextmv" or
"not_activated".
"""

# Check if the ampl_license_uuid file exists. NOTE: When running in Nextmv
# Cloud with a valid license, make sure to run on a premium execution
# class. Contact support for more information.
if os.path.isfile("ampl_license_uuid"):
with open("ampl_license_uuid") as file:
license = file.read().strip()

# If the license is not the template message, activate it.
if license != "secret-key-123":
modules.activate(license)
return "license"

# A valid AMPL license has not been configured. When running on Nextmv
# Cloud, use a special module.
system_info = uname()
if system_info.system == "Linux" and "aarch64" in system_info.machine:
modules.activate("nextmv")
return "nextmv"

return "demo"


def log(message: str) -> None:
"""Logs a message. We need to use stderr since stdout is used for the
solution."""
Expand Down Expand Up @@ -220,12 +252,5 @@ def write_output(output_path, output) -> None:
print(content)


def read_license_uuid() -> str:
"""Reads the license needed to authenticate."""

with open("ampl_license_uuid") as file:
return file.read().strip()


if __name__ == "__main__":
main()

0 comments on commit 3cf2d53

Please sign in to comment.