Skip to content

Commit bfcaa3c

Browse files
committed
noot
0 parents  commit bfcaa3c

File tree

7 files changed

+391
-0
lines changed

7 files changed

+391
-0
lines changed

.github/workflows/docker-build.yml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
name: Build and Push Docker Image
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
tags:
8+
- 'v*'
9+
pull_request:
10+
branches:
11+
- main
12+
13+
env:
14+
REGISTRY: ghcr.io
15+
IMAGE_NAME: ${{ github.repository }}
16+
17+
jobs:
18+
build-and-push:
19+
runs-on: ubuntu-latest
20+
permissions:
21+
contents: read
22+
packages: write
23+
24+
steps:
25+
- name: Checkout repository
26+
uses: actions/checkout@v4
27+
28+
- name: Log in to the Container registry
29+
uses: docker/login-action@v3
30+
with:
31+
registry: ${{ env.REGISTRY }}
32+
username: ${{ github.actor }}
33+
password: ${{ secrets.GITHUB_TOKEN }}
34+
35+
- name: Extract metadata
36+
id: meta
37+
uses: docker/metadata-action@v5
38+
with:
39+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
40+
tags: |
41+
type=ref,event=branch
42+
type=ref,event=pr
43+
type=semver,pattern={{version}}
44+
type=semver,pattern={{major}}.{{minor}}
45+
type=semver,pattern={{major}}
46+
type=raw,value=latest,enable={{is_default_branch}}
47+
48+
- name: Set up Docker Buildx
49+
uses: docker/setup-buildx-action@v3
50+
51+
- name: Build and push Docker image
52+
uses: docker/build-push-action@v5
53+
with:
54+
context: .
55+
platforms: linux/amd64
56+
push: true
57+
tags: ${{ steps.meta.outputs.tags }}
58+
labels: ${{ steps.meta.outputs.labels }}
59+
cache-from: type=gha
60+
cache-to: type=gha,mode=max

.gitignore

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Nix build results
2+
result
3+
result-*
4+
5+
# Docker build cache
6+
.dockerignore
7+
*.tar
8+
*.tar.gz
9+
10+
# OS files
11+
.DS_Store
12+
Thumbs.db
13+
14+
# Editor files
15+
*.swp
16+
*.swo
17+
*~
18+
.vscode/
19+
.idea/
20+
21+
# Temporary files
22+
*.tmp
23+
*.temp
24+
*.log

Dockerfile

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
FROM debian:bookworm-slim
2+
3+
SHELL ["/bin/bash", "-c"]
4+
ENV DEBIAN_FRONTEND=noninteractive
5+
6+
# Default to bash shell (other shells available at /usr/bin/fish and /usr/bin/zsh)
7+
ENV SHELL=/bin/bash \
8+
DOCKER_BUILDKIT=1
9+
10+
# Install the Docker apt repository
11+
RUN apt-get update && \
12+
apt-get upgrade --yes --no-install-recommends --no-install-suggests && \
13+
apt-get install --yes --no-install-recommends --no-install-suggests \
14+
ca-certificates && \
15+
rm -rf /var/lib/apt/lists/*
16+
COPY docker/docker-archive-keyring.gpg /usr/share/keyrings/docker-archive-keyring.gpg
17+
COPY docker/docker.list /etc/apt/sources.list.d/docker.list
18+
19+
# Install baseline packages
20+
RUN apt-get update && \
21+
apt-get install --yes --no-install-recommends --no-install-suggests \
22+
bash \
23+
build-essential \
24+
containerd.io \
25+
curl \
26+
docker-ce \
27+
docker-ce-cli \
28+
docker-buildx-plugin \
29+
docker-compose-plugin \
30+
htop \
31+
jq \
32+
locales \
33+
locales-all \
34+
man \
35+
python3 \
36+
python3-pip \
37+
software-properties-common \
38+
sudo \
39+
systemd \
40+
systemd-sysv \
41+
unzip \
42+
vim \
43+
wget \
44+
rsync \
45+
gnupg \
46+
lsb-release \
47+
ripgrep \
48+
fd-find \
49+
python3-dotenv-cli \
50+
atool \
51+
zip \
52+
p7zip-full \
53+
xz-utils \
54+
bzip2 \
55+
git git-lfs
56+
57+
# Enables Docker starting with systemd
58+
RUN systemctl enable docker
59+
60+
# Create a symlink for standalone docker-compose usage
61+
RUN ln -s /usr/libexec/docker/cli-plugins/docker-compose /usr/bin/docker-compose
62+
63+
# Generate the desired locale (en_US.UTF-8)
64+
RUN sed -i 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen && \
65+
locale-gen en_US.UTF-8 && \
66+
update-locale LANG=en_US.UTF-8
67+
68+
# Make typing unicode characters in the terminal work.
69+
ENV LANG=en_US.UTF-8
70+
ENV LANGUAGE=en_US.UTF-8
71+
ENV LC_ALL=en_US.UTF-8
72+
73+
# Remove any existing users and add a user `coder` so that you're not developing as the `root` user
74+
RUN useradd coder \
75+
--create-home \
76+
--shell=/bin/bash \
77+
--groups=docker \
78+
--uid=1000 \
79+
--user-group && \
80+
echo "coder ALL=(ALL) NOPASSWD:ALL" >>/etc/sudoers.d/nopasswd
81+
82+
USER coder
83+
84+
# Install mise
85+
ENV MISE_DATA_DIR="/home/coder/.local/share/mise"
86+
ENV MISE_CONFIG_DIR="/home/coder/.config/mise"
87+
ENV MISE_CACHE_DIR="/home/coder/.cache/mise"
88+
ENV MISE_INSTALL_PATH="/home/coder/.local/bin/mise"
89+
ENV PATH="/home/coder/.local/bin:/home/coder/.local/share/mise/shims:$PATH"
90+
91+
RUN curl https://mise.run | sh
92+
93+
# Set default command to bash
94+
CMD ["/bin/bash"]

Makefile

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
.PHONY: build push clean help
2+
3+
# Default target
4+
help:
5+
@echo "Available targets:"
6+
@echo " build - Build the devimage using Docker"
7+
@echo " push - Push the image to Docker Hub"
8+
@echo " clean - Clean up Docker build cache"
9+
@echo " help - Show this help message"
10+
11+
# Build the Docker image
12+
build:
13+
@echo "Building devimage with Docker..."
14+
docker build -t devimage:latest .
15+
16+
# Push the image to Docker Hub (requires login)
17+
push: build
18+
@echo "Pushing image to Docker Hub..."
19+
docker push devimage:latest
20+
21+
# Clean up Docker build cache
22+
clean:
23+
@echo "Cleaning up Docker build cache..."
24+
docker system prune -f

devimage.nix

Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
{ pkgs ? import <nixpkgs> { }
2+
, system ? builtins.currentSystem
3+
}:
4+
5+
let
6+
# Create the coder user configuration
7+
coderUser = {
8+
uid = 1000;
9+
gid = 1000;
10+
home = "/home/coder";
11+
shell = "${pkgs.bash}/bin/bash";
12+
};
13+
14+
# Mise installation script
15+
miseInstallScript = pkgs.writeScript "install-mise.sh" ''
16+
#!${pkgs.bash}/bin/bash
17+
set -e
18+
export HOME=/home/coder
19+
export MISE_DATA_DIR="$HOME/.local/share/mise"
20+
export MISE_CONFIG_DIR="$HOME/.config/mise"
21+
export MISE_CACHE_DIR="$HOME/.cache/mise"
22+
export MISE_INSTALL_PATH="$HOME/.local/bin/mise"
23+
24+
mkdir -p $HOME/.local/bin
25+
${pkgs.curl}/bin/curl -fsSL https://mise.run | ${pkgs.bash}/bin/bash
26+
'';
27+
28+
# Declaratively create user files
29+
userFiles = pkgs.runCommand "user-files" {} ''
30+
mkdir -p $out/etc
31+
32+
# Create /etc/passwd
33+
cat > $out/etc/passwd <<EOF
34+
root:x:0:0:root:/root:/bin/sh
35+
nobody:x:65534:65534:nobody:/var/empty:/bin/false
36+
coder:x:${toString coderUser.uid}:${toString coderUser.gid}:Coder User:${coderUser.home}:${coderUser.shell}
37+
EOF
38+
39+
# Create /etc/group
40+
cat > $out/etc/group <<EOF
41+
root:x:0:
42+
nobody:x:65534:
43+
coder:x:${toString coderUser.gid}:
44+
EOF
45+
46+
# Create /etc/shadow
47+
cat > $out/etc/shadow <<EOF
48+
root:!:19000:0:99999:7:::
49+
nobody:!:19000:0:99999:7:::
50+
coder:!:19000:0:99999:7:::
51+
EOF
52+
53+
chmod 0644 $out/etc/passwd $out/etc/group
54+
chmod 0600 $out/etc/shadow
55+
56+
# Create sudoers file
57+
mkdir -p $out/etc/sudoers.d
58+
echo "coder ALL=(ALL) NOPASSWD:ALL" > $out/etc/sudoers.d/nopasswd
59+
chmod 0440 $out/etc/sudoers.d/nopasswd
60+
'';
61+
62+
in
63+
pkgs.dockerTools.streamLayeredImage {
64+
name = "devimage";
65+
tag = "latest";
66+
67+
fromImage = pkgs.dockerTools.pullImage {
68+
imageName = "debian";
69+
imageDigest = "sha256:2424c1850714a4d94666ec928e24d86de958646737b1d113f5b2207be44d37d8";
70+
sha256 = "sha256-O6oFV3kh1WYF60Pv6nMGtJ/q3ujNbxxqLFpKzopfe48=";
71+
finalImageTag = "bookworm-slim";
72+
finalImageName = "debian";
73+
};
74+
75+
contents = pkgs.buildEnv {
76+
name = "image-root";
77+
paths = [
78+
userFiles # Include our declarative user configuration
79+
] ++ (with pkgs; [
80+
# Core system
81+
bash
82+
coreutils
83+
findutils
84+
gnugrep
85+
gawk
86+
gnused
87+
88+
# Build tools
89+
gcc
90+
gnumake
91+
cmake
92+
pkg-config
93+
94+
# Development tools
95+
git
96+
git-lfs
97+
curl
98+
wget
99+
rsync
100+
jq
101+
htop
102+
man
103+
sudo
104+
vim
105+
neovim
106+
unzip
107+
108+
# Language support
109+
python3
110+
python3Packages.pip
111+
112+
# Modern CLI tools
113+
ripgrep
114+
fd
115+
116+
# Archive tools
117+
atool
118+
zip
119+
p7zip
120+
xz
121+
bzip2
122+
123+
# System libraries
124+
cacert
125+
gnupg
126+
lsb-release
127+
128+
# Docker tools
129+
docker
130+
docker-compose
131+
132+
# Locale data
133+
glibcLocales
134+
]);
135+
pathsToLink = [ "/bin" "/etc" "/lib" "/share" "/usr" "/sbin" ];
136+
};
137+
138+
config = {
139+
Cmd = [ "${pkgs.bash}/bin/bash" ];
140+
141+
Env = [
142+
"DEBIAN_FRONTEND=noninteractive"
143+
"SHELL=/bin/bash"
144+
"DOCKER_BUILDKIT=1"
145+
"LANG=en_US.UTF-8"
146+
"LANGUAGE=en_US.UTF-8"
147+
"LC_ALL=en_US.UTF-8"
148+
"PATH=/home/coder/.local/share/mise/shims:/home/coder/.local/bin:/run/current-system/sw/bin:/nix/var/nix/profiles/default/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
149+
"HOME=/home/coder"
150+
"MISE_DATA_DIR=/home/coder/.local/share/mise"
151+
"MISE_CONFIG_DIR=/home/coder/.config/mise"
152+
"MISE_CACHE_DIR=/home/coder/.cache/mise"
153+
"MISE_INSTALL_PATH=/home/coder/.local/bin/mise"
154+
];
155+
156+
User = "coder";
157+
WorkingDir = "/home/coder";
158+
};
159+
160+
extraCommands = ''
161+
# Create home directory structure
162+
mkdir -p home/coder/.local/bin
163+
mkdir -p home/coder/.local/share/mise/shims
164+
mkdir -p home/coder/.config/mise
165+
mkdir -p home/coder/.cache/mise
166+
167+
# Create standard directories
168+
mkdir -p usr/bin usr/sbin bin sbin
169+
170+
# Create locale configuration
171+
mkdir -p etc/default
172+
echo "LANG=en_US.UTF-8" > etc/default/locale
173+
'';
174+
175+
fakeRootCommands = ''
176+
# Create home directory with proper ownership first
177+
mkdir -p ${coderUser.home}
178+
chown ${toString coderUser.uid}:${toString coderUser.gid} ${coderUser.home}
179+
180+
# Install mise as coder user
181+
sudo -u coder ${miseInstallScript}
182+
183+
# Ensure ownership of all home directory contents
184+
chown -R ${toString coderUser.uid}:${toString coderUser.gid} ${coderUser.home}
185+
'';
186+
187+
enableFakechroot = true;
188+
}

docker/docker-archive-keyring.gpg

2.7 KB
Binary file not shown.

0 commit comments

Comments
 (0)