Compare commits
32 Commits
b955384ebc
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
f8c5a5071d
|
|||
|
12a9bec916
|
|||
|
ccd1cafa80
|
|||
|
06491c1a02
|
|||
|
54534cceab
|
|||
|
b44b0c248c
|
|||
|
bc86a1d58c
|
|||
|
614168c903
|
|||
|
183ccc0072
|
|||
|
8b31b61380
|
|||
|
5f87d970f9
|
|||
|
f96fd2eff5
|
|||
|
3d4c258bb1
|
|||
|
9cd843f749
|
|||
|
18889e3d26
|
|||
|
b3215c96f3
|
|||
|
056ff220c5
|
|||
|
f67738b5ec
|
|||
|
2ca42d5add
|
|||
|
f895c11cbd
|
|||
|
5ce5004482
|
|||
|
e643f9974a
|
|||
|
d74f42b7fa
|
|||
|
75e1d916d2
|
|||
|
363355bfe0
|
|||
|
9edab5b046
|
|||
|
b07ae7ea7f
|
|||
|
955b5030e6
|
|||
|
0089c971f4
|
|||
|
16841bb334
|
|||
|
a1f7a46a73
|
|||
|
d8367d41cd
|
@@ -14,10 +14,10 @@ jobs:
|
||||
changes:
|
||||
runs-on: job-v2
|
||||
outputs:
|
||||
fedora: ${{ steps.filter.outputs.fedora == 'true' }}
|
||||
infra: ${{ steps.filter.outputs.infra == 'true' || steps.filter.outputs.fedora == 'true' }}
|
||||
go: ${{ steps.filter.outputs.go == 'true' || steps.filter.outputs.fedora == 'true' }}
|
||||
php: ${{ steps.filter.outputs.php == 'true' || steps.filter.outputs.fedora == 'true' }}
|
||||
base: ${{ steps.filter.outputs.base == 'true' }}
|
||||
infra: ${{ steps.filter.outputs.infra == 'true' || steps.filter.outputs.base == 'true' }}
|
||||
go: ${{ steps.filter.outputs.go == 'true' || steps.filter.outputs.base == 'true' }}
|
||||
php: ${{ steps.filter.outputs.php == 'true' || steps.filter.outputs.base == 'true' }}
|
||||
any_change: ${{ steps.filter.outputs.workflow == 'true' || github.event_name == 'schedule' || github.event_name == 'workflow_dispatch'}}
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
@@ -26,14 +26,14 @@ jobs:
|
||||
with:
|
||||
filters: |
|
||||
workflow: ['.gitea/workflows/build.yaml']
|
||||
fedora: ['containers/fedora/**']
|
||||
base: ['containers/base/**']
|
||||
infra: ['containers/infra/**']
|
||||
go: ['containers/go/**']
|
||||
php: ['containers/php/**']
|
||||
|
||||
base-image:
|
||||
needs: [changes]
|
||||
if: ${{ needs.changes.outputs.fedora == 'true' || needs.changes.outputs.any_change == 'true' }}
|
||||
if: ${{ needs.changes.outputs.base == 'true' || needs.changes.outputs.any_change == 'true' }}
|
||||
runs-on: job-v2
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
@@ -47,10 +47,10 @@ jobs:
|
||||
id: build
|
||||
uses: job79/buildah-build@65b3793a1370c1ccd74a5c0d090d70eb9637a4ef
|
||||
with:
|
||||
image: job79/fedora
|
||||
image: job79/base
|
||||
tags: ${{ github.ref_name }}
|
||||
context: ./containers/fedora
|
||||
containerfiles: ./containers/fedora/Containerfile
|
||||
context: ./containers/base
|
||||
containerfiles: ./containers/base/Containerfile
|
||||
platforms: linux/amd64
|
||||
- name: Push
|
||||
uses: redhat-actions/push-to-registry@v2
|
||||
|
||||
32
containers/base/Containerfile
Normal file
32
containers/base/Containerfile
Normal file
@@ -0,0 +1,32 @@
|
||||
FROM quay.io/fedora/fedora:44
|
||||
|
||||
# === install system packages ===
|
||||
RUN --mount=type=cache,id=dnf-cache,target=/var/cache/libdnf5 \
|
||||
dnf update -y && \
|
||||
dnf -y --setopt=keepcache=1 --setopt=install_weak_deps=False install \
|
||||
bash-completion git-core fzf curl awk jq fd-find rg unzip which \
|
||||
host-spawn wl-copy gcc
|
||||
|
||||
RUN LAZYGIT_VERSION=$(curl -s "https://api.github.com/repos/jesseduffield/lazygit/releases/latest" | jq -r .tag_name | sed 's/^v//') && \
|
||||
curl -sL "https://github.com/jesseduffield/lazygit/releases/latest/download/lazygit_${LAZYGIT_VERSION}_linux_x86_64.tar.gz" | tar xz -C /usr/local/bin lazygit && \
|
||||
curl -sL "https://github.com/jorgerojas26/lazysql/releases/latest/download/lazysql_Linux_x86_64.tar.gz" | tar xz -C /usr/local/bin lazysql && \
|
||||
curl -sL "https://github.com/neovim/neovim/releases/download/nightly/nvim-linux-x86_64.tar.gz" | tar xz -C /usr/local --strip-components=1
|
||||
|
||||
COPY config/bin /usr/local/bin
|
||||
|
||||
# === setup user ===
|
||||
RUN useradd -ms /bin/bash user && \
|
||||
echo 'user ALL=(ALL) NOPASSWD: ALL' > /etc/sudoers.d/user && \
|
||||
mkdir -p /run/user/1000 && \
|
||||
chown user:user /run/user/1000
|
||||
|
||||
USER user
|
||||
WORKDIR /home/user
|
||||
|
||||
RUN mkdir -p .config .local .cache && \
|
||||
git clone https://git.plabble.org/Job79/neovim-config.git .config/nvim
|
||||
|
||||
COPY --chown=user:user config/bashrc .bashrc
|
||||
COPY --chown=user:user config/git .config/git/config
|
||||
|
||||
VOLUME /home/user
|
||||
21
containers/base/config/bashrc
Normal file
21
containers/base/config/bashrc
Normal file
@@ -0,0 +1,21 @@
|
||||
source /etc/bashrc
|
||||
|
||||
# === bash settings ===
|
||||
set -o vi
|
||||
bind -m vi-insert '"\C-l": clear-screen'
|
||||
|
||||
# === environment ===
|
||||
export PS1="\[\e[30;46m\] \h | \w \[\e[0;36m\]\[\e[m\] " \
|
||||
EDITOR="nvim" \
|
||||
WAYLAND_DISPLAY="wayland-0" \
|
||||
XDG_RUNTIME_DIR="/run/user/1000" \
|
||||
SSH_AUTH_SOCK="/run/user/1000/ssh-auth-sock" \
|
||||
TZ="Europe/Amsterdam" \
|
||||
FZF_CTRL_T_COMMAND="fd --type f --hidden --exclude .git --exclude Library --exclude .cache" \
|
||||
FZF_ALT_C_COMMAND="fd --type d --hidden --exclude .git --exclude Library --exclude .cache"
|
||||
|
||||
# === aliases and functions ===
|
||||
alias vi=nvim
|
||||
post() { curl -sF "content=<-" "https://paste.plabble.org/$2?lang=$1" && echo; }
|
||||
|
||||
eval "$(fzf --bash)"
|
||||
6
containers/base/config/bin/host
Executable file
6
containers/base/config/bin/host
Executable file
@@ -0,0 +1,6 @@
|
||||
#!/bin/bash
|
||||
export DBUS_SESSION_BUS_ADDRESS="unix:path=/tmp/bus"
|
||||
|
||||
cmd="${0##*/}"
|
||||
[[ "$cmd" == "host" ]] && unset cmd
|
||||
exec host-spawn -cwd "${PWD/#$HOME/$HOST_HOME}" ${cmd:+"$cmd"} "$@"
|
||||
@@ -1,26 +0,0 @@
|
||||
FROM quay.io/fedora/fedora:44
|
||||
|
||||
# === install system packages ===
|
||||
RUN --mount=type=cache,id=dnf-cache,target=/var/cache/libdnf5 \
|
||||
dnf update -y && \
|
||||
dnf copr enable -y atim/lazygit && \
|
||||
dnf copr enable -y atim/lazydocker && \
|
||||
dnf copr enable -y gierth/tools-golang && \
|
||||
dnf copr enable agriffis/neovim-nightly && \
|
||||
dnf -y --setopt=keepcache=1 install procps ping bash-completion glibc-langpack-en \
|
||||
host-spawn dbus-launch \
|
||||
zoxide git npm neovim awk jq unzip fd-find lazygit lazydocker lazysql
|
||||
|
||||
# === setup user ===
|
||||
RUN useradd -ms /bin/bash user && echo 'user ALL=NOPASSWD: ALL' > /etc/sudoers && mkdir -p /run/user/1000 && chown user:user /run/user/1000
|
||||
|
||||
USER user
|
||||
WORKDIR /home/user
|
||||
|
||||
RUN mkdir .config .local .cache && \
|
||||
git clone https://git.plabble.org/Job79/neovim-config.git .config/nvim
|
||||
COPY --chown=user:user config/bashrc .bashrc
|
||||
COPY --chown=user:user config/git .config/git/config
|
||||
COPY config/bin /usr/local/bin
|
||||
|
||||
VOLUME /home/user
|
||||
@@ -1,16 +0,0 @@
|
||||
. /etc/bashrc
|
||||
|
||||
# === environment ===
|
||||
export EDITOR=nvim \
|
||||
WAYLAND_DISPLAY=wayland-0 \
|
||||
XDG_RUNTIME_DIR=/run/user/1000 \
|
||||
SSH_AUTH_SOCK=/run/user/1000/ssh-auth-sock \
|
||||
PS1="\[\e[30;46m\] \h | \w \[\e[0;36m\]\[\e[m\] " \
|
||||
TZ="Europe/Amsterdam"
|
||||
|
||||
# === aliases and functions ===
|
||||
alias vi=nvim
|
||||
post() { curl -sF "content=<-" "https://paste.plabble.org/$2?lang=$1" && echo; }
|
||||
|
||||
eval "$(zoxide init --cmd cd bash)"
|
||||
eval "$(fzf --bash)"
|
||||
@@ -1,4 +0,0 @@
|
||||
#!/bin/bash
|
||||
export DBUS_SESSION_BUS_ADDRESS=unix:path=/tmp/bus
|
||||
host-spawn -cwd "${PWD/#$HOME/$HOST_HOME}" \
|
||||
$([ "$(basename "$0")" != "host" ] && echo "$(basename "$0")") "$@"
|
||||
@@ -1,8 +1,10 @@
|
||||
ARG TAG
|
||||
FROM job79/fedora:${TAG}
|
||||
FROM job79/base:${TAG}
|
||||
USER root
|
||||
|
||||
RUN --mount=type=cache,id=dnf-cache,target=/var/cache/libdnf5 \
|
||||
dnf -y --setopt=keepcache=1 install go
|
||||
RUN GO_VERSION=$(curl -sL "https://go.dev/VERSION?m=text" | head -n 1 | tr -d '\r\n') && \
|
||||
curl -sL "https://go.dev/dl/${GO_VERSION}.linux-amd64.tar.gz" | tar xz -C /usr/local && \
|
||||
ln -sf /usr/local/go/bin/go /usr/local/bin/go && \
|
||||
ln -sf /usr/local/go/bin/gofmt /usr/local/bin/gofmt
|
||||
|
||||
USER user
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
#!/bin/bash
|
||||
arg "-v $HOME/Documents/go:/home/user/Documents/go"
|
||||
run_opts+=("-v" "$HOME/Documents/go:/home/user/Documents/go")
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
ARG TAG
|
||||
FROM job79/fedora:${TAG}
|
||||
FROM job79/base:${TAG}
|
||||
USER root
|
||||
|
||||
RUN --mount=type=cache,id=dnf-cache,target=/var/cache/libdnf5 \
|
||||
dnf -y --setopt=keepcache=1 install kubectl k9s openssl age "$(curl -s https://api.github.com/repos/getsops/sops/releases/latest | jq -r ".assets[] | select(.name | test(\"sops-.*.$(arch).rpm\$\")) | .browser_download_url")" && \
|
||||
dnf -y --setopt=keepcache=1 --setopt=install_weak_deps=False install \
|
||||
just kubectl k9s openssl age "$(curl -s https://api.github.com/repos/getsops/sops/releases/latest | jq -r ".assets[] | select(.name | test(\"sops-.*.$(arch).rpm\$\")) | .browser_download_url")" && \
|
||||
curl -sL https://talos.dev/install | sh && \
|
||||
curl -s https://fluxcd.io/install.sh | bash
|
||||
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
#!/bin/bash
|
||||
arg "-v $HOME/Documents/infra:/home/user/Documents/infra"
|
||||
run_opts+=("-v" "$HOME/Documents/infra:/home/user/Documents/infra")
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
ARG TAG
|
||||
FROM job79/fedora:${TAG}
|
||||
FROM job79/base:${TAG}
|
||||
USER root
|
||||
|
||||
RUN --mount=type=cache,id=dnf-cache,target=/var/cache/libdnf5 \
|
||||
dnf -y --setopt=keepcache=1 install php composer && \
|
||||
dnf -y --setopt=keepcache=1 install php composer npm && \
|
||||
composer global require laravel/installer
|
||||
|
||||
USER user
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
#!/bin/bash
|
||||
arg "-v $HOME/Documents/php:/home/user/Documents/php"
|
||||
run_opts+=("-v" "$HOME/Documents/php:/home/user/Documents/php")
|
||||
|
||||
154
devc.sh
154
devc.sh
@@ -1,122 +1,78 @@
|
||||
#!/bin/bash
|
||||
# =============================================== #
|
||||
# devc.sh v2.0; job79 #
|
||||
# Dev container enter script. Handles setting up #
|
||||
# different dev containers, resuming sessions and #
|
||||
# automatic container updates. #
|
||||
# devc.sh v2.1; job79, maurice #
|
||||
# Dev container entry script. #
|
||||
# =============================================== #
|
||||
set -eu
|
||||
log() { printf '\e[%sm%s\e[0m %s\n' "${3:-36}" "${2:-○}" "$1"; }
|
||||
arg() { echo -n " $@"; }
|
||||
set -euo pipefail
|
||||
log() { echo -e "\e[36m○\e[0m $1"; }
|
||||
die() { echo -e "\e[31mx\e[0m $1" && exit 1; }
|
||||
|
||||
# run_args returns the container run arguments required for
|
||||
# starting a new container.
|
||||
# default_args configures standard container options.
|
||||
default_args() {
|
||||
arg "--name $name"
|
||||
arg "--hostname $name"
|
||||
run_opts+=(
|
||||
"--name" "$name"
|
||||
"--hostname" "$name"
|
||||
"--pull=newer" # Update image.
|
||||
"--userns=keep-id" # Map host user.
|
||||
"-v" "$name:/home/user:copy" # Persistent home volume.
|
||||
"-v" "dnf-cache:/var/cache/libdnf5" # Cache dnf metadata.
|
||||
)
|
||||
|
||||
# Pull newer container image if available.
|
||||
arg "--pull=newer"
|
||||
# Unix sockets require SELinux label disable.
|
||||
[[ -d /sys/fs/selinux ]] && run_opts+=("--security-opt" "label=disable")
|
||||
|
||||
# Use keep-id so the container user matches the host user.
|
||||
arg "--userns=keep-id"
|
||||
# Desktop integration (Wayland, SSH).
|
||||
[[ -e "/run/user/$UID/wayland-0" ]] && run_opts+=("-v" "/run/user/$UID/wayland-0:/run/user/1000/wayland-0")
|
||||
[[ -e "${SSH_AUTH_SOCK:-}" ]] && run_opts+=("-v" "$SSH_AUTH_SOCK:/run/user/1000/ssh-auth-sock")
|
||||
|
||||
# Disable selinux labeling so unix sockets can be mounted
|
||||
# without problems.
|
||||
[ -d /sys/fs/selinux ] && arg "--security-opt label=disable"
|
||||
|
||||
# Mount the wayland socket. Required to get the system
|
||||
# clipboard (wl-copy) and gui applications working.
|
||||
[ -e "/run/user/$UID/wayland-0" ] && arg "-v /run/user/$UID/wayland-0:/run/user/1000/wayland-0"
|
||||
|
||||
# Mount the ssh socket to get ssh working.
|
||||
[ -e "$SSH_AUTH_SOCK" ] && arg "-v $SSH_AUTH_SOCK:/run/user/1000/ssh-auth-sock"
|
||||
|
||||
# Make the user home dir a volume so it survives container
|
||||
# restarts. Use copy to keep the files from the image.
|
||||
arg "-v $name:/home/user:copy"
|
||||
|
||||
# If there is custom configuration for the container, load
|
||||
# it here.
|
||||
config_file="$(dirname "$(realpath "$0")")/containers/$name/config.sh"
|
||||
[ -f "$config_file" ] && source "${config_file}"
|
||||
# Load custom container config.
|
||||
local config_file="${BASH_SOURCE[0]%/*}/containers/$name/config.sh"
|
||||
[[ -f "$config_file" ]] && source "$config_file" || true
|
||||
}
|
||||
|
||||
# param_args returns the container run arguments based on the
|
||||
# arguments provided to this script.
|
||||
# param_args parses CLI arguments into podman run options.
|
||||
param_args() {
|
||||
while test $# -gt 0; do
|
||||
while (($# > 0)); do
|
||||
case "$1" in
|
||||
-gpu) # Enable gpu acceleration.
|
||||
arg "--device /dev/dri" ;;
|
||||
-host-spawn) # Enable spawning host commands from inside the container using host-spawn.
|
||||
arg "-v /run/user/$UID/bus:/tmp/bus"
|
||||
arg "-e HOST_HOME=$HOME" # Used to translate paths.
|
||||
;;
|
||||
-container-sock) # Mount container sock into the container.
|
||||
case "$(basename "$engine")" in
|
||||
podman) arg "-v /run/user/$UID/podman/podman.sock:/var/run/docker.sock" ;;
|
||||
docker) arg "-v /var/run/docker.sock:/var/run/docker.sock" ;;
|
||||
esac
|
||||
;;
|
||||
-x11) # Enable X11 support.
|
||||
arg "-v /tmp/.X11-unix:/tmp/.X11-unix"
|
||||
arg "-v $XAUTHORITY:/run/user/1000/.Xauthority:ro"
|
||||
arg "-e DISPLAY=$DISPLAY"
|
||||
arg "-e XAUTHORITY=/run/user/1000/.Xauthority"
|
||||
;;
|
||||
-mnt) # Mount directory.
|
||||
shift
|
||||
arg "-w /mnt/"
|
||||
arg "-v $1:/mnt/$([ ! -d "$1" ] && echo 'file')"
|
||||
;;
|
||||
*) # Use unknown arguments as container arguments.
|
||||
arg "$1" ;;
|
||||
-gpu) run_opts+=("--device" "/dev/dri") ;;
|
||||
-host-spawn) run_opts+=("-v" "/run/user/$UID/bus:/tmp/bus" "-e" "HOST_HOME=$HOME") ;;
|
||||
-container-sock) run_opts+=("-v" "$XDG_RUNTIME_DIR/podman/podman.sock:/var/run/docker.sock") ;;
|
||||
-x11) run_opts+=("-v" "/tmp/.X11-unix:/tmp/.X11-unix" "-v" "$XAUTHORITY:/run/user/1000/.Xauthority:ro" "-e" "DISPLAY=$DISPLAY" "-e" "XAUTHORITY=/run/user/1000/.Xauthority") ;;
|
||||
-mnt) shift && run_opts+=("-w" "/mnt/" "-v" "$1:/mnt/$([[ -d "$1" ]] || echo "file")") ;;
|
||||
*) run_opts+=("$1") ;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
}
|
||||
|
||||
### MAIN ###
|
||||
engine="$(command -v podman || command -v docker)"
|
||||
[ -z "$engine" ] && echo "no container engine found" && exit 1
|
||||
main() {
|
||||
local state_file="$HOME/.local/share/devc-previous-container"
|
||||
local image="${1:-}"
|
||||
|
||||
# Get the devcontainer name from the first argument. If not
|
||||
# provided, use the last used name when possible.
|
||||
if [[ $# -gt 0 ]] && [[ ${1:-} != -* ]]; then
|
||||
image="$1"
|
||||
[[ "$image" != *:* ]] && image="$image:main"
|
||||
echo "$image" >"$HOME/.local/share/devc-previous-container"
|
||||
# Resolve container name (CLI arg > Last used > Error).
|
||||
if [[ $image && $image != -* ]]; then
|
||||
shift
|
||||
elif [ -f "$HOME/.local/share/devc-previous-container" ]; then
|
||||
image=$(<"$HOME/.local/share/devc-previous-container")
|
||||
else
|
||||
log "no container name specified" 'x' 31
|
||||
exit 1
|
||||
fi
|
||||
name="${image%:*}"
|
||||
[[ $image != *:* ]] && image+=":main"
|
||||
echo "$image" >"$state_file"
|
||||
elif [[ -f $state_file ]]; then
|
||||
image=$(<$state_file)
|
||||
else
|
||||
die "no container name specified"
|
||||
fi
|
||||
local name="${image%:*}"
|
||||
|
||||
# Get container registry from the DEVC_REGISTRY env
|
||||
# variable.
|
||||
if [ -n "${DEVC_REGISTRY:-}" ]; then
|
||||
registry="$DEVC_REGISTRY"
|
||||
else
|
||||
log "registry unknown; set the DEVC_REGISTRY environment variable" 'x' 31
|
||||
exit 1
|
||||
fi
|
||||
# Start/Restart if not running or if arguments change configuration.
|
||||
if [[ -z "$(podman ps -q -f name="^$name$" -f status=running)" ]] || (($# > 0)); then
|
||||
log "starting $image..."
|
||||
|
||||
# Get container command from the DEVC_COMMAND env variable
|
||||
# if set, else use bash -l.
|
||||
if [ -z "${DEVC_COMMAND:-}" ]; then
|
||||
DEVC_COMMAND="bash -l"
|
||||
fi
|
||||
default_args
|
||||
param_args "$@"
|
||||
|
||||
# When container is not running or arguments are provided,
|
||||
# recreate it.
|
||||
if [ "$($engine container inspect "$name" -f {{.State.Running}} 2>&1)" != 'true' ] || [[ $# -gt 0 ]]; then
|
||||
log "starting devcontainer..."
|
||||
$engine container rm -f -t 0 "$name" 1>/dev/null
|
||||
$engine run -td $(default_args) $(param_args $@) "$registry/$image"
|
||||
fi
|
||||
[[ -n "${DEVC_REGISTRY:-}" ]] || die "registry unknown; set the DEVC_REGISTRY environment variable"
|
||||
podman run --replace --stop-timeout 0 -td "${run_opts[@]}" "$DEVC_REGISTRY/$image"
|
||||
fi
|
||||
|
||||
$engine exec --detach-keys "ctrl-@,ctrl-@" -it "$name" ${DEVC_COMMAND:-}
|
||||
exec podman exec --detach-keys "ctrl-@,ctrl-@" -it "$name" ${DEVC_COMMAND:-bash -l}
|
||||
}
|
||||
|
||||
main "$@"
|
||||
|
||||
Reference in New Issue
Block a user