generated from kurtosis-tech/package-template-repo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.star
116 lines (97 loc) · 3.69 KB
/
main.star
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
postgres = import_module("github.com/kurtosis-tech/postgres-package/main.star")
nginx = import_module("github.com/kurtosis-tech/nginx-package/main.star")
laravel_app = import_module("/laravel-app/app.star")
# Postgres defaults
DEFAULT_POSTGRES_SERVICE_NAME = "postgres"
DEFAULT_POSTGRES_IMAGE_NAME = "postgres:alpine"
DEFAULT_POSTGRES_USER = "postgres"
DEFAULT_POSTGRES_PASSWORD = "secretdatabasepassword"
DEFAULT_POSTGRES_DB_NAME = "laravel-db"
# Nginx defaults
DEFAULT_NGINX_SERVICE_NAME = "nginx"
DEFAULT_NGINX_IMAGE_NAME = "nginx:latest"
DEFAULT_NGINX_CONFIG_FILE_ARTIFACT = "/nginx/default.conf"
DEFAULT_NGINX_ROOT_DIRPATH = "/var/www/public"
DEFAULT_NGINX_PORT_NUMBER=80
# Laravel app defaults
DEFAULT_LARAVEL_APP_SERVICE_NAME="laravel-app"
DEFAULT_LARAVEL_APP_PORT_NUMBER=9000
def run(
plan,
laravel_app_service_name=DEFAULT_LARAVEL_APP_SERVICE_NAME,
postgres_service_name=DEFAULT_POSTGRES_SERVICE_NAME,
postgres_image=DEFAULT_POSTGRES_IMAGE_NAME,
postgres_db_name=DEFAULT_POSTGRES_DB_NAME,
postgres_user=DEFAULT_POSTGRES_USER,
postgres_password=DEFAULT_POSTGRES_PASSWORD,
nginx_service_name= DEFAULT_NGINX_SERVICE_NAME,
nginx_image_name=DEFAULT_NGINX_IMAGE_NAME,
):
"""
Starts this Laravel example application.
Args:
laravel_app_service_name (string): the Laravel app's service name (default: laravel-app)
postgres_service_name (string): the Postgres's service name (default: postgres)
postgres_image (string): the Postgres's container image name and label (default: postgres:alpine)
postgres_user (string): the Postgres's user name (default: postgres)
postgres_password (string): the Postgres's password (default: secretdatabasepassword)
postgres_db_name (string): the Postgres's db name (default: laravel-db)
nginx_service_name (string): the Nginx's service name (default: nginx)
nginx_image_name (string): the Nginx's container image name and label (default: nginx:latest)
"""
# run the application's db
postgres_db = postgres.run(
plan,
service_name=postgres_service_name,
image=postgres_image,
user=postgres_user,
password=postgres_password,
database=postgres_db_name,
)
laravel_app_service = laravel_app.run(plan, laravel_app_service_name, postgres_db, postgres_password)
# upload Nginx config template
nginx_templates = plan.upload_files(
src="./nginx/template",
name="nginx-templates",
)
env_vars = {
"NGINX_PORT_NUMBER": "{}".format(DEFAULT_NGINX_PORT_NUMBER),
"NGINX_ROOT_FOLDER": DEFAULT_NGINX_ROOT_DIRPATH,
"LARAVEL_APP_HOST_NAME": laravel_app_service_name,
"LARAVEL_APP_PORT_NUMBER": "{}".format(DEFAULT_LARAVEL_APP_PORT_NUMBER),
}
# upload root files
nginx_public_files = plan.upload_files(
src="/laravel-app/files/public",
name="nginx_public_files",
)
file_artifacts = {
"/etc/nginx/templates": nginx_templates,
DEFAULT_NGINX_ROOT_DIRPATH: nginx_public_files,
}
nginx_port_id = "http"
nginx_args = {
"name":nginx_service_name,
"image":nginx_image_name,
"port_id":nginx_port_id,
"port_number":DEFAULT_NGINX_PORT_NUMBER,
"file_artifacts":file_artifacts,
"env_vars":env_vars,
}
nginx.run(
plan,
args= nginx_args,
)
get_request_recipe = GetHttpRequestRecipe(
port_id = nginx_port_id,
endpoint = "/",
)
plan.wait(
service_name = nginx_service_name,
recipe = get_request_recipe,
field = "code",
assertion = "==",
target_value = 200,
interval = "1s",
timeout = "5m",
)