Skip to content

Commit 198a363

Browse files
committed
fix: improvements and deploy container (#3)
- Add deploy image and correct various stuff.
1 parent 46aa635 commit 198a363

23 files changed

Lines changed: 1296 additions & 330 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
.prettierrc.yaml
2222
.yamllint.yaml
2323
.typos.toml
24+
.ruff-cache
2425

2526
# General build folder.
2627
.output

README.md

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,18 +73,39 @@ following features.
7373

7474
# Usage
7575

76+
## With Container
77+
78+
```bash
79+
mkdir repo
80+
podman run -it -v "$(pwd)/repo:/workspace" \
81+
ghcr.io/sdsc-ordes/repository-template:latest \
82+
-t "<language>" -d "." [-- ["args-to-copier"...]]
83+
```
84+
85+
> [!WARNING]
86+
>
87+
> **DO NOT try to use `docker`** (and for other things too 😆) for the above, it
88+
> does not do
89+
> [user namespacing](https://docs.docker.com/engine/security/userns-remap/) and
90+
> it will create `root`-owned files. We do not support this now. Just use
91+
> `podman`!
92+
93+
See [arguments explanations here](#arguments).
94+
7695
## Cloning
7796
7897
Clone this repository to some place of your choice.
7998
8099
Apply the templates with `copier` using the following:
81100
82-
```shell
101+
```bash
83102
cd repo && git pull
84-
just create <language> <destination> [args...]
103+
just create -t "<language>" -d "<destination>" [-- ["args-to-copier"...]]
85104
```
86105
87-
where
106+
See [arguments explanations here](#arguments).
107+
108+
## Arguments
88109
89110
- `<destination>` is the destination folder where you want to place this new
90111
repository.
@@ -97,8 +118,13 @@ where
97118
- [`rust`](./src/rust): For a Rust toolchain with `cargo`
98119
- [`go`](./src/go): For a default Go toolchain.
99120
100-
- `[args...]` are optional arguments passed to `copier`. If you want to
101-
overwrite by default use `-w` and not answer `Y` all the time.
121+
- `[args-to-copier...]` are optional arguments passed to `copier`. If you want
122+
to overwrite by default use `-w` and not answer `Y` all the time and `-l` to
123+
apply all defaults to inspect:
124+
125+
```shell
126+
just create -t <language> -d <destination> -- -w -l
127+
```
102128
103129
## Containerized
104130

docs/development-guide.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,14 @@ Other scopes then the one in the specification are:
1818
- `python`: If the commit targets only the `python` template.
1919
- `rust`: If the commit targets only the `rust` template.
2020
- `go`: If the commit targets only the `go` template.
21+
22+
## Testing
23+
24+
Run
25+
26+
```shell
27+
just test-all
28+
```
29+
30+
To update the Nix Flakes, run
31+
`REPOSITORY_TEMPLATE_UPDATE_FLAKES=true just test-all`.

justfile

Lines changed: 26 additions & 181 deletions
Original file line numberDiff line numberDiff line change
@@ -3,76 +3,49 @@ set shell := ["bash", "-cue"]
33
comp_dir := justfile_directory()
44
root_dir := `git rev-parse --show-toplevel`
55
output_dir := root_dir / ".output"
6-
flake_dir := "./tools/nix"
6+
flake_dir := root_dir / "./tools/nix"
7+
8+
mod maintenance "./tools/just/maintenance.just"
79

810
# Default target if you do not specify a target.
911
default:
10-
just --list
12+
just --list --unsorted
1113

1214
# Create a new project from a template.
13-
create template="python" output_dir="build":
14-
just develop just create-impl "$@"
15-
16-
# Create a new project from a template with all default answers.
17-
create-default template="python" output_dir="build":
18-
just develop just create-impl "$@" -l
19-
20-
[private]
21-
create-impl *args:
22-
#!/usr/bin/env bash
23-
set -eu
24-
source ./tools/ci/general.sh
25-
26-
template="$1"
27-
destination="$(realpath "$2")" # Make absolute (resolve symlinks etc...)
28-
args=("${@:3}")
15+
create *args:
16+
just develop ./tools/scripts/create.sh "$@"
2917

30-
[[ "$template" =~ generic|rust|go|python ]] ||
31-
ci::die "No such template '$template' to template"
32-
33-
mkdir -p "$destination"
34-
cd "{{root_dir}}"
35-
36-
ci::print_info "Rendering 'generic' template ... "
37-
copier copy --trust "${args[@]}" \
38-
"src/generic" "$destination" \
39-
--data "project_language=$template" ||
40-
ci::die "Could not apply template '$template'."
41-
ci::print_info "Rendering 'generic' template completed."
18+
# Format the whole repository.
19+
format *args:
20+
"{{root_dir}}/tools/scripts/setup-config-files.sh"
21+
nix run --accept-flake-config {{flake_dir}}#treefmt -- "$@"
4222

43-
if [ "$template" != "generic" ]; then
44-
answer_file="$destination/tools/configs/copier/answers/generic.yaml"
23+
# Setup the repository.
24+
setup *args:
25+
just maintenance::setup "$@"
4526

46-
ci::print_info "Rendering '$template' template ..."
47-
copier copy --trust "${args[@]}" \
48-
"src/$template" "$destination" \
49-
--data "project_authors=$(yq -r ".project_authors" "$answer_file")" \
50-
--data "project_hosts=$(yq -r ".project_hosts" "$answer_file")" \
51-
--data "project_version=$(yq -r ".project_version" "$answer_file")" \
52-
--data "project_description=$(yq -r ".project_description" "$answer_file")" \
53-
--data "project_url=$(yq -r ".project_url" "$answer_file")" ||
54-
ci::die "Could not apply template '$template'."
55-
ci::print_info "Rendering '$template' template completed."
56-
fi
27+
# Clean output folder.
28+
clean:
29+
rm -rf ./.output
5730

58-
if ! git -C "$destination" rev-parse --show-toplevel &>/dev/null; then
59-
# If we are not inside a Git repo we need to init.
60-
ci::print_info "Initializing Git repo '$destination'"
61-
git -C "$destination" init || ci::die "Could not initialize Git repo."
62-
fi
31+
# Test a template.
32+
test template="python":
33+
just maintenance::test "{{template}}"
6334

64-
if [ "$(git -C "$destination" rev-parse --show-toplevel 2>/dev/null)" == "$destination" ]; then
65-
# If we are inside the top level, add the files directly.
66-
ci::print_info "Staging all files."
67-
git -C "$destination" add . || ci::die "Could not stage all files."
68-
fi
35+
# Test everything.
36+
test-all:
37+
just maintenance::test-all
6938

39+
# Show all packages configured in the Nix `flake.nix`.
40+
nix-list *args:
41+
cd tools/nix && nix flake --no-pure-eval show
7042

7143
# Enter the default Nix development shell.
7244
develop *args:
7345
just nix-develop default "$@"
7446

7547
# Enter the Nix development shell `$1` and execute the command `${@:2}`.
48+
[private]
7649
nix-develop *args:
7750
#!/usr/bin/env bash
7851
set -eu
@@ -82,131 +55,3 @@ nix-develop *args:
8255
nix develop --no-pure-eval --accept-flake-config \
8356
"{{flake_dir}}#$shell" \
8457
--command "${args[@]}"
85-
86-
# Format the whole repository.
87-
format *args:
88-
"{{root_dir}}/tools/scripts/setup-config-files.sh"
89-
nix run --accept-flake-config {{flake_dir}}#treefmt -- "$@"
90-
91-
# Setup the repository.
92-
setup *args:
93-
./tools/scripts/setup.sh
94-
95-
# Test all templates.
96-
test-all:
97-
just test generic
98-
just test python
99-
just test rust
100-
101-
# Test the code scaffolding.
102-
test template="python": setup
103-
#!/usr/bin/env bash
104-
set -eu
105-
source "{{root_dir}}/tools/ci/general.sh"
106-
107-
ci::print_info "Running test '{{template}}'"
108-
ci::print_info "======================"
109-
build_dir="{{output_dir}}/{{template}}"
110-
cd "{{root_dir}}" && rm -rf "$build_dir"
111-
112-
uv run copier copy --trust -w \
113-
--data "project_language={{template}}" \
114-
--defaults \
115-
src/generic \
116-
"$build_dir"
117-
118-
if [ "{{template}}" != "generic" ]; then
119-
answer_file="$build_dir/tools/configs/copier/answers/generic.yaml"
120-
uv run copier copy --trust -w \
121-
--data "project_authors=$(yq -r ".project_authors" "$answer_file")" \
122-
--data "project_hosts=$(yq -r ".project_hosts" "$answer_file")" \
123-
--data "project_version=$(yq -r ".project_version" "$answer_file")" \
124-
--data "project_description=$(yq -r ".project_description" "$answer_file")" \
125-
--data "project_url=$(yq -r ".project_url" "$answer_file")" \
126-
--defaults \
127-
"src/{{template}}" \
128-
"$build_dir"
129-
fi
130-
131-
# Test the templated output.
132-
cd "${build_dir}" &&
133-
git init && git add . && \
134-
git commit -a -m "init"
135-
136-
just develop just setup
137-
just develop just format
138-
just develop just lint
139-
just develop just build
140-
just develop just run
141-
142-
cp tools/nix/flake.lock "{{root_dir}}/src/{{template}}/tools/nix/flake.lock"
143-
if [ "{{template}}" == "python" ]; then
144-
cp uv.lock "{{root_dir}}/src/{{template}}/uv.lock"
145-
elif [ "{{template}}" == "go" ]; then
146-
cp go.work.sum "{{root_dir}}/src/{{template}}/go.work.sum"
147-
cp src/tool/go.sum "{{root_dir}}/src/{{template}}/src/{{{{ package_name }}/go.sum"
148-
elif [ "{{template}}" == "rust" ]; then
149-
cp Cargo.lock "{{root_dir}}/src/{{template}}/Cargo.lock"
150-
fi
151-
152-
git clean -df
153-
154-
if ! git diff --exit-code --quiet . ; then
155-
echo "We have changes in the build folder."
156-
fi
157-
158-
# Create and upload the code scaffolding.
159-
upload-all template="python":
160-
just upload generic
161-
just upload rust
162-
just upload go
163-
just upload python
164-
165-
# Create and upload the code scaffolding.
166-
upload template="python": setup
167-
#!/usr/bin/env bash
168-
set -eu
169-
source "{{root_dir}}/tools/ci/general.sh"
170-
171-
temp_dir=$(mktemp -d)
172-
function cleanup() {
173-
[ ! -d "$temp_dir" ] || {
174-
ci::print_info "removing temp dir"
175-
rm -rf "$temp_dir"
176-
}
177-
}
178-
trap cleanup EXIT
179-
180-
ci::print_info "Upload '{{template}}'"
181-
ci::print_info "======================"
182-
build_dir="$temp_dir/{{template}}"
183-
184-
cd "{{root_dir}}" && rm -rf "$build_dir" && mkdir -p "$build_dir"
185-
just create-impl "{{template}}" "$build_dir" -l -f
186-
187-
cd "$build_dir"
188-
189-
# Add WARNING
190-
cat <(
191-
echo "> [!WARNING]"
192-
echo "> This is a demo rendering of the [\`{{template}}\` template here](https://github.com/sdsc-ordes/repository-template#{{template}}-template)"
193-
echo
194-
cat README.md
195-
) > README.md.mod && mv README.md.mod README.md
196-
197-
git init &&
198-
just format &&
199-
git add . &&
200-
git commit -a -m "init"
201-
202-
git remote add origin \
203-
"https://github.com/sdsc-ordes/repository-template-{{template}}.git"
204-
205-
branch="main"
206-
if ! ci::is_running; then
207-
branch="test"
208-
git switch -c "$branch"
209-
fi
210-
211-
git checkout "$branch"
212-
git push origin --force

src/.jinja/common/justfile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ build_dir := output_dir / "build"
88

99
# Default target if you do not specify a target.
1010
default:
11-
just --list
11+
just --list --unsorted
1212

1313
# Enter the default Nix development shell and execute the command `"$@`.
1414
develop *args:
@@ -23,6 +23,9 @@ format *args:
2323
setup *args:
2424
cd "{{root_dir}}" && ./tools/scripts/setup.sh
2525

26+
# Show all packages configured in the Nix `flake.nix`.
27+
nix-list *args:
28+
cd tools/nix && nix flake --no-pure-eval show
2629

2730
# Enter the Nix `devShell` with name `$1` and execute the command `${@:2}` (default command is '$SHELL')
2831
[private]

0 commit comments

Comments
 (0)