-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a function to extract your host ip
- Loading branch information
1 parent
7bc4a40
commit 76b41dc
Showing
6 changed files
with
172 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
use flake |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
## Background | ||
|
||
This tool is based on a [post][learn-nix]. It's a good proven way to extract a host ip from a | ||
docker container (that is using host networking). | ||
|
||
### Function | ||
|
||
Add this function definition to any set of prompts that might need to extract the host IP address. | ||
|
||
```yaml | ||
- container: | ||
image: vonwig/what-is-my-ip:latest | ||
name: what-is-my-ip | ||
description: Get the host IP address for this machine. | ||
``` | ||
[learn-nix]:https://fzakaria.com/2024/07/05/learn-nix-the-fun-way.html | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
''; | ||
}; | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
``` |