Skip to content

Commit

Permalink
Update build tasks and docs with latest usecase
Browse files Browse the repository at this point in the history
  • Loading branch information
kachick committed Mar 16, 2024
1 parent a0b426e commit cb627b7
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 18 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Usage is written in README.md in each images directory.

## Container Images

| Name | Build in loccal | Pull from container registry and run |
| ----------------------------------------------- | --------------------------------------------- | --------------------------------------------------------------------------------------- |
| [ubuntu-nix-sudoer](images/ubuntu-nix-sudoer) | `task try IMAGE=ubuntu-nix-sudoer USER=user` | `podman run --user=user --rm -it ghcr.io/kachick/ubuntu-nix-sudoer:latest` |
| [ubuntu-nix-systemd](images/ubuntu-nix-systemd) | `task try IMAGE=ubuntu-nix-systemd USER=user` | `podman run --rm ghcr.io/kachick/ubuntu-nix-systemd:latest &"` # Why bg? See the README |
| Name | Build in loccal | Examples |
| ----------------------------------------------- | ---------------------------- | ----------------------------------------------------------------------------------------------------------- |
| [ubuntu-nix-systemd](images/ubuntu-nix-systemd) | `task try:systemd USER=user` | [dotfiles](https://github.com/kachick/dotfiles/blob/f81983534aeb9f0db80932f5ae73bd59793b8af4/README.md#L47) |
| [ubuntu-nix-sudoer](images/ubuntu-nix-sudoer) | `task try:sudoer USER=user` | `podman run --user=user --rm -it ghcr.io/kachick/ubuntu-nix-sudoer:latest` |
7 changes: 5 additions & 2 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,12 @@ tasks:
- nixpkgs-fmt --check ./*.nix
- trivy config --exit-code 1 .
- shellcheck ./images/*/*.bash
try:
'try:systemd':
cmds:
- ./images/{{.IMAGE}}/try.bash '{{.IMAGE}}' '{{.USER}}'
- ./images/ubuntu-nix-systemd/try.bash '{{.USER}}'
'try:sudoer':
cmds:
- ./images/ubuntu-nix-sudoer/try.bash '{{.USER}}'
deps:
cmds:
- nix --version
Expand Down
8 changes: 4 additions & 4 deletions images/ubuntu-nix-sudoer/try.bash
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

set -euxo pipefail

image=$1
user=$2
image_tag=ubuntu-nix-sudoer
user="$1"

podman build --tag "$image" --build-arg username="$user" --file ./images/"$image"/Containerfile .
podman run --interactive --tty --rm --name "$image" "$image"
podman build --tag "$image_tag" --build-arg username="$user" --file "./images/${image_tag}/Containerfile" .
podman run --interactive --tty --rm "$image_tag"
1 change: 1 addition & 0 deletions images/ubuntu-nix-systemd/Containerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ RUN curl --proto '=https' --tlsv1.2 -sSf -L https://install.determinate.systems/
--no-start-daemon \
--no-confirm

# TODO: Consider to extract from this repository
ARG username="user"
RUN useradd --no-log-init --create-home $username

Expand Down
5 changes: 3 additions & 2 deletions images/ubuntu-nix-systemd/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
Keep systemd in background and use it with another user

```bash
podman run --rm ghcr.io/kachick/ubuntu-nix-systemd:latest &
podman exec --user=user -it "$(podman ps --sort=created --format {{.Names}} | tail -1)" bash
container_id="$(podman run --rm --detach ghcr.io/kachick/ubuntu-nix-systemd:latest)"
sleep 1
podman exec --user=user -it "$container_id" bash
```

Make sure non root and non sudoers can run nix features
Expand Down
13 changes: 7 additions & 6 deletions images/ubuntu-nix-systemd/try.bash
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

set -euxo pipefail

image=$1
user=$2
image_tag=ubuntu-nix-systemd
user="$1"

podman build --tag "$image" --build-arg username="$user" --file ./images/"$image"/Containerfile .
podman run --rm --name "$image" --detach "$image"
podman exec --user "$user" --interactive --tty "$image" bash
podman stop "$image"
podman build --tag "$image_tag" --build-arg username="$user" --file "./images/${image_tag}/Containerfile" .
container_id="$(podman run --rm --detach "$image_tag")"
sleep 1 # Wait systemd to be ready
podman exec --user "$user" --interactive --tty "$container_id" bash
podman stop "$container_id"

0 comments on commit cb627b7

Please sign in to comment.