Skip to content

Commit

Permalink
Add a function to extract your host ip
Browse files Browse the repository at this point in the history
  • Loading branch information
slimslenderslacks committed Jul 10, 2024
1 parent 7bc4a40 commit a7098b5
Show file tree
Hide file tree
Showing 5 changed files with 154 additions and 0 deletions.
1 change: 1 addition & 0 deletions functions/what_is_my_ip/.envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
use flake
32 changes: 32 additions & 0 deletions functions/what_is_my_ip/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@

# syntax = docker/dockerfile:1.4
FROM nixos/nix:2.21.1@sha256:3f6c77ee4d2c82e472e64e6cd7087241dc391421a0b42c22e6849c586d5398d9 AS builder

WORKDIR /tmp/build
RUN mkdir /tmp/nix-store-closure

# ignore SC2046 because the output of nix-store -qR will never have spaces - this is safe here
# hadolint ignore=SC2046
RUN --mount=type=cache,target=/nix,from=nixos/nix:2.21.1,source=/nix \
--mount=type=cache,target=/root/.cache \
--mount=type=bind,target=/tmp/build \
<<EOF
nix \
--extra-experimental-features "nix-command flakes" \
--option filter-syscalls false \
--extra-trusted-substituters "https://cache.iog.io" \
--extra-trusted-public-keys "hydra.iohk.io:f/Ea+s+dFdN+3Y/G+FDgSq+a5NEWhJGzdjvKNGv0/EQ=" \
--show-trace \
--log-format raw \
build . --out-link /tmp/output/result
cp -R $(nix-store -qR /tmp/output/result) /tmp/nix-store-closure
EOF

FROM scratch

WORKDIR /app

COPY --from=builder /tmp/nix-store-closure /nix/store
COPY --from=builder /tmp/output/ /app/

ENTRYPOINT ["/app/result/bin/entrypoint"]
61 changes: 61 additions & 0 deletions functions/what_is_my_ip/flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions functions/what_is_my_ip/flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
description = "what is my ip";

inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.11";
flake-utils.url = "github:numtide/flake-utils";
};

outputs = { self, nixpkgs, flake-utils, ...}@inputs:

flake-utils.lib.eachDefaultSystem
(system:
let
pkgs = import nixpkgs {
inherit system;
};

in rec
{
packages = rec {

default = pkgs.writeShellScriptBin "entrypoint" ''
${pkgs.curl}/bin/curl -s http://httpbin.org/get | \
${pkgs.jq}/bin/jq --raw-output .origin
'';
};
});
}
32 changes: 32 additions & 0 deletions functions/what_is_my_ip/runbook.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Background

The `write_file` function has wo parameters.

* `path`: is a relative path from some project_root
* `content`: is the content that should be written into the file

## Usage

This function should be given a rw bind mount for the root of a project.

```sh
docker run --rm --entrypoint /app/result/bin/entrypoint vonwig/what-is-my-ip:latest
```

## Build

```sh
docker build -t vonwig/what-is-my-ip:latest .
```

```sh
# docker:command=build

docker buildx build \
--builder hydrobuild \
--platform linux/amd64,linux/arm64 \
--tag vonwig/what-is-my-ip:latest \
--file Dockerfile \
--push .
docker pull vonwig/what-is-my-ip:latest
```

0 comments on commit a7098b5

Please sign in to comment.