Skip to content

Commit 2b12d2c

Browse files
committed
A few addition/fixes
1 parent 478204e commit 2b12d2c

File tree

9 files changed

+42
-38
lines changed

9 files changed

+42
-38
lines changed

Makefile

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,29 +22,32 @@ docw::
2222
build-release::
2323
./cargo build --release
2424

25-
l01::
26-
RUST_LOG=debug RUST_BACKTRACE=1 ./cargo run -- docker login --config tests/01_trivial-backend-no-storage/opday.toml -f ./secrets/docker-config.json
25+
login-01::
26+
RUST_LOG=debug RUST_BACKTRACE=1 ./cargo run -- docker login --config tests/01_trivial-backend-no-storage/opday.toml -f ./.secrets/docker-config.json
2727

28-
a01::
28+
all-01::
2929
RUST_LOG=debug RUST_BACKTRACE=1 ./cargo run -- docker build-push-deploy --build-arg BACKEND_TAG=0.0.4 --config tests/01_trivial-backend-no-storage/opday.toml
3030

31-
b01::
31+
build-01::
3232
RUST_LOG=debug RUST_BACKTRACE=1 ./cargo run -- docker build --build-arg BACKEND_TAG=0.0.4 --config tests/01_trivial-backend-no-storage/opday.toml
3333

34-
p01::
34+
push-01::
3535
RUST_LOG=debug RUST_BACKTRACE=1 ./cargo run -- docker push --build-arg BACKEND_TAG=0.0.4 --config tests/01_trivial-backend-no-storage/opday.toml
3636

37-
d01::
37+
deploy-01::
3838
RUST_LOG=debug RUST_BACKTRACE=1 ./cargo run -- docker deploy --build-arg BACKEND_TAG=0.0.4 --config tests/01_trivial-backend-no-storage/opday.toml
3939

40-
b02::
40+
all-02::
41+
RUST_LOG=debug RUST_BACKTRACE=1 ./cargo run -- docker build-push-deploy --build-arg BACKEND_TAG=0.0.4 --build-arg NGINX_TAG=0.0.1 --config tests/02_simple-backend-with-database/opday.toml
42+
43+
build-02::
4144
RUST_LOG=debug RUST_BACKTRACE=1 ./cargo run -- docker build --build-arg BACKEND_TAG=0.0.4 --build-arg NGINX_TAG=0.0.1 --config tests/02_simple-backend-with-database/opday.toml
4245

43-
p02::
46+
push-02::
4447
RUST_LOG=debug RUST_BACKTRACE=1 ./cargo run -- docker push --build-arg BACKEND_TAG=0.0.4 --build-arg NGINX_TAG=0.0.1 --config tests/02_simple-backend-with-database/opday.toml
4548

46-
d02::
49+
deploy-02::
4750
RUST_LOG=debug RUST_BACKTRACE=1 ./cargo run -- docker deploy --build-arg BACKEND_TAG=0.0.4 --build-arg NGINX_TAG=0.0.1 --config tests/02_simple-backend-with-database/opday.toml
4851

49-
c02::
52+
curl-02::
5053
curl http://46.101.98.131/api/v1/make-database-call

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ Scope of applying this tool:
4444
* Less than 100 virtual machines for service. More hosts might become an issue for straightforward push architecture.
4545
* Up to 100 daily releases
4646
* Base-level infra with trivial sharding and replication for storage and databases. Everything above might be more suitable for custom or cloud-managed services.
47+
* It's more flexible for wide kind of services, but more verbose in configuring `Docker` and `docker-compose` files than specialiazed tools like Vercel for frontend and NodeJS.
4748

4849
# User guide
4950

src/exec.rs

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,30 +16,32 @@ pub fn execute_short_command(
1616
build_arg: &Vec<String>,
1717
) -> Result<String, Box<dyn std::error::Error>> {
1818
let mut exec_command = Command::new(program);
19-
exec_command.args(command);
19+
exec_command.args(command.clone());
2020
for build_arg_item in build_arg {
2121
let parts: Vec<&str> = build_arg_item.splitn(2, '=').collect();
2222
if parts.len() < 2 {
2323
panic!("Invalid build-arg without `=`: `{}`", build_arg_item)
2424
}
2525
exec_command.env(parts[0], parts[1]);
2626
}
27+
28+
// TODO: correct quoting of command args
29+
let command_str = String::new() + program + " " + &command.join(" ");
30+
2731
debug!(
28-
"Start command: {:?} envs:{:?} args:{:?}",
29-
program,
32+
"Start command: {} envs:{:?}",
33+
command_str,
3034
&exec_command.get_envs(),
31-
&exec_command.get_args(),
3235
);
3336
let output = exec_command.output().expect("failed to execute process");
3437

3538
let status = output.status;
3639
let stdout = String::from_utf8_lossy(&output.stdout).to_string();
3740
let stderr = String::from_utf8_lossy(&output.stderr).to_string();
3841
debug!(
39-
"Executed command: {:?} envs:{:?} args:{:?} {:?} {:?} {:?}",
40-
program,
42+
"Executed command: {:?} envs:{:?} status: {:?} out: {:?} err: {:?}",
43+
command_str,
4144
&exec_command.get_envs(),
42-
&exec_command.get_args(),
4345
status,
4446
stdout,
4547
stderr
@@ -48,10 +50,9 @@ pub fn execute_short_command(
4850
return Err(Box::new(std::io::Error::new(
4951
std::io::ErrorKind::Other,
5052
format!(
51-
"Command failed: {:?} envs:{:?} args:{:?} status:{:?} stdout:{:?} stderr:{:?}",
52-
program,
53+
"Command failed: {:?} envs:{:?} status:{:?} stdout:{:?} stderr:{:?}",
54+
command_str,
5355
&exec_command.get_envs(),
54-
&exec_command.get_args(),
5556
status,
5657
stdout,
5758
stderr
@@ -75,12 +76,14 @@ pub fn execute_command(
7576
}
7677
exec_command.env(parts[0], parts[1]);
7778
}
79+
80+
// TODO: correct quoting of command args
81+
let command_str = String::new() + program + " " + &command.join(" ");
7882
debug!(
79-
"Start command: {:?} {:?} envs:{:?} args:{:?}",
83+
"Start command: {} envs: {:?} cmd: {}",
8084
program,
81-
&command,
82-
&exec_command.get_envs(),
83-
&exec_command.get_args(),
85+
&exec_command.get_envs(), // TODO: filter out secrets
86+
&command_str,
8487
);
8588

8689
let mut process = exec_command
@@ -94,7 +97,6 @@ pub fn execute_command(
9497
std::thread::spawn(move || {
9598
let mut stdout = stdout;
9699
let mut stderr = stderr;
97-
debug!("out");
98100
let mut closing = false;
99101
loop {
100102
let mut buffer = [0; 1024];
@@ -142,17 +144,17 @@ pub fn execute_command(
142144
let stdout = String::from_utf8_lossy(&output.stdout).to_string();
143145
let stderr = String::from_utf8_lossy(&output.stderr).to_string();
144146
debug!(
145-
"Executed command:{:?} args:{:?} status:{:?}",
146-
program, &command, status
147+
"Executed command: {} status: {:?} cmd: {}",
148+
program, status, &command_str
147149
);
148150
if !status.success() {
149151
return Err(Box::new(std::io::Error::new(
150152
std::io::ErrorKind::Other,
151153
format!(
152-
"Command failed: {:?} envs:{:?} args:{:?} status:{:?} stdout:{:?} stderr:{:?}",
154+
"Command failed: {:?} envs:{:?} cmd:{:?} status:{:?} stdout:{:?} stderr:{:?}",
153155
program,
154156
&exec_command.get_envs(),
155-
&exec_command.get_args(),
157+
&command_str,
156158
status,
157159
stdout,
158160
stderr

src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ mod tests {
128128
args,
129129
case::just_docker(vec!["docker"]),
130130
case::just_docker_build(vec!["", "docker", "build"]),
131-
case::config_abefore_sub_command(vec!["", "--config", "myconfig", "docker", "build"]),
131+
case::config_before_sub_command(vec!["", "--config", "myconfig", "docker", "build"]),
132132
case::config_after_sub_command(vec!["", "docker", "--config", "myconfig", "build"]),
133133
case::config_after_sub_sub_command(vec!["", "docker", "build", "--config", "myconfig"]),
134134
case::config_after_sub_sub_command_plus_build_arg(vec!["", "docker", "build", "--config", "myconfig", "--build-arg", "BACKEND_TAG=0.0.1"]),
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
version: '3.7'
22
services:
33
backend:
4+
# build: '!reset null'
45
image: registry.digitalocean.com/frlr/dkrpublish/test-backend:${BACKEND_TAG}
5-
build: '!reset null'
66
command: uvicorn app:app --host 0.0.0.0 --port 8000
77
restart: unless-stopped
88
ports:
99
- "8000:8000"
1010
volumes: !reset []
1111
environment:
1212
ENVIRONMENT: prod
13-
DATABASE_URL: psycopg2://postgres:[email protected]:5432/postgres

tests/01_trivial-backend-no-storage/docker-compose.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ services:
99
- ./backend:/backend
1010
environment:
1111
ENVIRONMENT: local
12-
DATABASE_URL: psycopg2://postgres:[email protected]:5432/postgres
1312

1413
volumes:
1514
backend:

tests/01_trivial-backend-no-storage/test-backend/Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ WORKDIR /usr/src/app
55

66
ENV PYTHONUNBUFFERED 1
77

8-
RUN pip install poetry==1.2.2
8+
RUN pip install poetry==1.8.3
99

1010
COPY ./pyproject.toml .
1111

12-
RUN POETRY_VIRTUALENVS_CREATE=false poetry install --with=dev -n --no-root
12+
RUN POETRY_VIRTUALENVS_CREATE=false poetry install -n --no-root
1313

1414
EXPOSE 8000
1515

tests/02_simple-backend-with-database/backend/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ WORKDIR /usr/src/app
55

66
ENV PYTHONUNBUFFERED 1
77

8-
RUN pip install poetry==1.8.2
8+
RUN pip install poetry==1.8.3
99

1010
COPY ./pyproject.toml .
1111

tests/02_simple-backend-with-database/docker-compose.override-run.prod.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
version: '3.7'
22
services:
33
backend:
4+
# build: '!reset null'
45
image: registry.digitalocean.com/frlr/opday/02-backend:${BACKEND_TAG}
5-
build: '!reset null'
66
command: uvicorn app:app --host 0.0.0.0 --port 8000
77
restart: unless-stopped
88
ports:
@@ -13,8 +13,8 @@ services:
1313
DATABASE_URL: psycopg2://postgres:postgres@postgres:5432/postgres
1414

1515
nginx:
16+
# build: '!reset null'
1617
image: registry.digitalocean.com/frlr/opday/02-nginx:${NGINX_TAG}
17-
build: '!reset null'
1818
ports:
1919
- "80:80"
2020
- "443:443"

0 commit comments

Comments
 (0)