Skip to content

Commit

Permalink
Fix build
Browse files Browse the repository at this point in the history
  • Loading branch information
infogulch committed Dec 27, 2024
1 parent 542a02e commit 7886fde
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 33 deletions.
7 changes: 4 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,15 @@ COPY ./test/migrations /app/migrations/
COPY ./test/config.json /app/

USER root:root
RUN mkdir /app/dataw; chown $USER:$USER /app/dataw
USER $USER:$USER
RUN mkdir /app/dataw

VOLUME /app/dataw

RUN ["/app/xtemplate", "--version"]

CMD ["--loglevel", "-4", "-d", "DB:sql:sqlite3:file:./dataw/test.sqlite", "-d", "FS:fs:./data", "--config-file", "config.json"]
WORKDIR /app/dataw

CMD ["--loglevel", "-4", "--config-file", "../config.json"]

###

Expand Down
54 changes: 33 additions & 21 deletions make_tool.cue
Original file line number Diff line number Diff line change
Expand Up @@ -69,25 +69,25 @@ task: build: {
task: run: {
vars: #vars

rmdataw: file.RemoveAll & {path: "\(vars.testdir)/dataw"}
mkdataw: file.Mkdir & {path: "\(vars.testdir)/dataw", $after: rmdataw.$done}
mktemp: file.MkdirTemp & {dir: vars.testdir, pattern: "temp-"}

start: exec.Run & {
cmd: ["bash", "-c", "./xtemplate --loglevel -4 --config-file config.json &>xtemplate.log &"]
dir: vars.testdir
$after: mkdataw.$done
cmd: ["bash", "-c", "../xtemplate --loglevel -4 --config-file ../config.json &>xtemplate.log &"]
dir: mktemp.path
$after: mktemp.$done
}
}

task: test: {
vars: #vars

port: int | *8080
port: int | *8080
reportpath: string | *"report"

list: file.Glob & {glob: "\(vars.testdir)/tests/*.hurl"}
ready: exec.Run & {cmd: "curl -X GET --retry-all-errors --retry 5 --retry-connrefused --retry-delay 1 http://localhost:\(port)/ready --silent", stdout: "OK"}
hurl: exec.Run & {
cmd: ["hurl", "--continue-on-error", "--no-output", "--test", "--report-html", "report", "--connect-to", "localhost:8080:localhost:\(port)"] + list.files
cmd: ["hurl", "--continue-on-error", "--no-output", "--test", "--report-html", reportpath, "--connect-to", "localhost:8080:localhost:\(port)"] + list.files
dir: vars.testdir
after: ready.$done
}
Expand All @@ -107,7 +107,7 @@ task: build_test: {

build: task.build & {"vars": vars, outfile: "\(vars.testdir)/xtemplate"}
run: task.run & {"vars": vars, start: $after: build.gobuild.$done}
test: task.test & {"vars": vars, ready: $after: run.start.$done}
test: task.test & {"vars": vars, reportpath: "\(run.mktemp.path)/report", ready: $after: run.start.$done}
kill: exec.Run & {cmd: "pkill xtemplate", $after: test.hurl.$done}
}

Expand Down Expand Up @@ -153,15 +153,22 @@ task: build_docker: {
task: test_docker: {
vars: #vars

mktemp: file.MkdirTemp & {dir: vars.testdir, pattern: "temp-"}

build: exec.Run & {
cmd: ["docker", "build", "-t", "xtemplate-test", "--target", "test", "--build-arg", "LDFLAGS=\(vars.ldflags)", "."]
dir: vars.rootdir
}
run: exec.Run & {
cmd: ["docker", "run", "-d", "--rm", "--name", "xtemplate-test", "-p", "8081:80", "xtemplate-test"]
cmd: ["bash", "-c", "docker run -d --rm --name xtemplate-test -p 8081:80 -v \(mktemp.path):/app/dataw xtemplate-test"]
$after: build.$done
}
test: task.test & {"vars": vars, port: 8081, ready: $after: run.$done}
logs: exec.Run & {
cmd: ["bash", "-c", "docker logs xtemplate-test &>docker.log"]
dir: mktemp.path
$after: run.$done
}
test: task.test & {"vars": vars, port: 8081, reportpath: "\(mktemp.path)/report", ready: $after: run.$done}
stop: exec.Run & {cmd: "docker stop xtemplate-test", $after: test.hurl.$done} // be nice if we can always run this even if previous steps fail
}

Expand Down Expand Up @@ -195,13 +202,12 @@ task: build_caddy: {
task: run_caddy: {
vars: #vars

rmdataw: file.RemoveAll & {path: "\(vars.testdir)/dataw"}
mkdataw: file.Mkdir & {path: "\(vars.testdir)/dataw", $after: rmdataw.$done}
mktemp: file.MkdirTemp & {dir: vars.testdir, pattern: "temp-"}

start: exec.Run & {
cmd: ["bash", "-c", "./caddy start --config caddy.json &>xtemplate.caddy.log"]
dir: vars.testdir
$after: mkdataw.$done
cmd: ["bash", "-c", "../caddy start --config ../caddy.json &>caddy.log"]
dir: mktemp.path
$after: mktemp.$done
}
}

Expand All @@ -210,7 +216,7 @@ task: build_test_caddy: {

build: task.build_caddy & {"vars": vars}
run: task.run_caddy & {"vars": vars, start: $after: build.xbuild.$done}
test: task.test & {"vars": vars, port: 8082, ready: $after: run.start.$done}
test: task.test & {"vars": vars, port: 8082, reportpath: "\(run.mktemp.path)/report", ready: $after: run.start.$done}
kill: exec.Run & {cmd: "pkill caddy", $after: test.hurl.$done} // is there a better way?
}

Expand All @@ -223,14 +229,20 @@ command: {
command: ci: {
cfg: meta

tempdirs: file.Glob & {glob: "\(cfg.vars.testdir)/temp-*"}
for tempdir in tempdirs.files {
("delete-" + tempdir): file.RemoveAll & {path: tempdir}
}

gotest: task.gotest & {"vars": cfg.vars}

build_test: task.build_test & {"vars": cfg.vars}
build_test_caddy: task.build_test_caddy & {"vars": cfg.vars, run: rmdataw: $after: build_test.kill.$done}
build_test: task.build_test & {"vars": cfg.vars, run: mktemp: $after: tempdirs.$done}
build_test_caddy: task.build_test_caddy & {"vars": cfg.vars, run: mktemp: $after: tempdirs.$done}
test_docker: task.test_docker & {"vars": cfg.vars, mktemp: $after: tempdirs.$done}

dist: task.dist & {"vars": cfg.vars, rmdist: $after: build_test.kill.$done}
pass: build_test.kill.$done && build_test_caddy.kill.$done && test_docker.stop.$done

test_docker: task.test_docker & {"vars": cfg.vars}
build_docker: task.build_docker & {"vars": cfg.vars, build: $after: test_docker.stop.$done}
dist: task.dist & {"vars": cfg.vars, rmdist: $after: pass}
build_docker: task.build_docker & {"vars": cfg.vars, build: $after: pass}
push_docker: task.push_docker & {tags: build_docker.tags} & {[=~"^push"]: $after: build_docker.build.$done}
}
1 change: 1 addition & 0 deletions test/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
report
*.log
*.sqlite
temp-*
11 changes: 6 additions & 5 deletions test/caddy.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,31 @@
{
"handler": "xtemplate",
"minify": true,
"templates_dir": "../templates",
"databases": [
{
"name": "DB",
"driver": "sqlite3",
"connstr": "file:./dataw/test.sqlite"
"connstr": "file:./test.sqlite"
}
],
"directories": [
{
"name": "FS",
"path": "./data"
"path": "../data"
},
{
"name": "FSW",
"path": "./dataw"
"path": "."
},
{
"name": "Migrations",
"path": "./migrations"
"path": "../migrations"
}
],
"flags": [
{
"name": "KV",
"name": "Flags",
"values": {
"a": "1",
"b": "2",
Expand Down
9 changes: 5 additions & 4 deletions test/config.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
{
"templates_dir": "../templates",
"directories": [
{
"name": "FS",
"path": "./data"
"path": "../data"
},
{
"name": "FSW",
"path": "./dataw"
"path": "."
},
{
"name": "Migrations",
"path": "./migrations"
"path": "../migrations"
}
],
"databases": [
{
"name": "DB",
"driver": "sqlite3",
"connstr": "file:./dataw/test.sqlite"
"connstr": "file:./test.sqlite"
}
],
"flags": [
Expand Down

0 comments on commit 7886fde

Please sign in to comment.