Files
mans fc0e3fdb68
Build docker container / Build image (push) Successful in 5m14s
Fix flake
2026-08-05 13:43:43 +02:00

75 lines
2.1 KiB
Nix

{
description = "ip-svc development and build environment";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-26.05";
flake-utils.url = "github:numtide/flake-utils";
};
outputs = { self, nixpkgs, flake-utils }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs { inherit system; };
in
{
packages = rec {
default = ip-svc;
ip-svc = pkgs.buildGoModule {
pname = "ip-svc";
version = "0.1.0";
src = ./.;
vendorHash = null;
env = {
CGO_ENABLED = "0";
};
};
dockerImage = pkgs.dockerTools.buildLayeredImage {
name = "ip-svc";
tag = "latest";
contents = [ default ];
config = {
Cmd = [ "${default}/bin/ip-svc" ];
ExposedPorts = {
"8080/tcp" = {};
};
Env = [
"IPV4_ENDPOINT=https://ip4.mziesel.nl/json"
"IPV6_ENDPOINT=https://ip6.mziesel.nl/json"
];
};
};
build-and-push = pkgs.writeShellScriptBin "build-and-push" ''
set -e
echo "Building Docker image with Nix..."
nix build .#dockerImage
echo "Loading image into Docker..."
docker load < result
TODAY=$(date +'%Y-%m-%d')
echo "Tagging Docker image..."
docker tag ip-svc:latest ''${REGISTRY}/''${REPO_OWNER}/''${IMAGE_NAME}:''${TODAY}
docker tag ip-svc:latest ''${REGISTRY}/''${REPO_OWNER}/''${IMAGE_NAME}:latest
echo "Pushing to registry..."
docker push ''${REGISTRY}/''${REPO_OWNER}/''${IMAGE_NAME}:''${TODAY}
docker push ''${REGISTRY}/''${REPO_OWNER}/''${IMAGE_NAME}:latest
'';
};
devShells.default = pkgs.mkShell {
buildInputs = with pkgs; [
go_1_26
air
gopls
];
};
}
);
}