diff --git a/README.md b/README.md index a9137c5..06a1786 100644 --- a/README.md +++ b/README.md @@ -34,3 +34,13 @@ Collection of Docker image + Compose recipes and related utilities in one monore | --- | --- | --- | --- | | `mkdocs-material` | [README](./docker/mkdocs-material/Dockerfile), [Dockerfile](./docker/mkdocs-material/Dockerfile), [Mkdocs theme docs](https://squidfunk.github.io/mkdocs-material) | Custom image for `mkdocs-material` with Node.js and other tools @ajhalili2006 used on GitLab CI | `python:3.12-alpine` | | `pkgops-alpine` | [README](./docker/pkgops-alpine/README.md), [Dockerfile](./docker/pkgops-alpine/Dockerfile) | My Alpine Linux Docker image for `aports` development. | + +## Build + +Use the provided build script to locally build images via Docker (disable BuildKit with `DOCKER_BUILDKIT=0`). + +```bash +scripts/build [tag] +``` + +Add additional `docker build` flags via `DOCKER_BUILD_ARGS` variable as needed. diff --git a/docker/devenv/README.md b/docker/devenv/README.md new file mode 100644 index 0000000..9e512e7 --- /dev/null +++ b/docker/devenv/README.md @@ -0,0 +1,58 @@ +# ~ajhalili2006's custom devenv images + +## Build + +You need at least 2 GB of storage and a stable and fast internet connection +to build + +> [!note] +> It's best to run the scripts at the root of the repo (or use `direnv` for this purpose) instead of prefixing it with `$(git rev-parse --show-toplevel)/`. +> You may also run into issues if the output of `git rev-parse --show-toplevel` has spaces in it. + +### Base image + +For base image: + +```bash +$(git rev-parse --show-toplevel)/scripts/build devenv/base [custom-image-name] +``` + +By default, the built image will be tagged with `dock.mau.dev/andreijiroh-dev/docker-images/devenv/base:localdev` which +you'll need on building subsequent images. + +**Supported build args**: + +* `BUILDPACK_DEPS_TAG`: Use this to lock into specific Ubuntu LTS release at specific SHA-256 digest of the image. +* `dotfiles` - Git-over-HTTPS clone URL of your dotfiles repository that compatible with `yadm`. +* `dotfilesBranch` - Branch name from your dotfiles repo if you seperate configuration files between environments via branches. + +### Google Cloud Shell + +> [!warning] +> The `gcr.io/cloudshell-images/cloudshell` base image weights at 22.44 GB, so you may need to spare some additional GBs of storage +> since we're doing `apt-get upgrade` behind the scenes. + +```bash +scripts/build devenv/cloudshell + +# on Google Cloud Shell +cd docker/devenv/cloudshell && cloudshell env build-local +``` + +### Gitpod workspace image + +To build Gitpod-optmized image: + +```bash +# To use your local build, pass --build-arg flag as value of DOCKER_BUILD_ARGS +# when running scripts/build. +DOCKER_BUILD_ARGS="--build-arg base=dock.mau.dev/andreijiroh-dev/docker-images/devenv/base:localdev" $(git rev-parse --show-toplevel)/scripts/build devenv/gitpod +``` + +Once built, you may want to use it to run a debug workspace in Gitpod. + +```bash +# You may need to authenicate with your preferred Docker registry for the script +# to work properly. +script/publish-to-staging dock.mau.dev/andreijiroh-dev/docker-images/devenv/gitpod:localdev +``` diff --git a/docker/devenv/base/Dockerfile b/docker/devenv/base/Dockerfile new file mode 100644 index 0000000..caa73f6 --- /dev/null +++ b/docker/devenv/base/Dockerfile @@ -0,0 +1,74 @@ +ARG BUILDPACK_DEPS_TAG=noble +FROM buildpack-deps:${BUILDPACK_DEPS_TAG} + +USER root + +# Get the utility scripts from gitpod for use during the build. +RUN curl -o /usr/local/bin/install-packages -fsSL https://github.com/gitpod-io/workspace-images/raw/main/base/install-packages \ + && curl -o /usr/local/bin/upgrade-packages -fsSL https://github.com/gitpod-io/workspace-images/raw/main/base/install-packages \ + && chmod +x /usr/local/bin/install-packages \ + && chmod +x /usr/local/bin/upgrade-packages + +RUN yes | unminimize \ + && install-packages \ + zip \ + unzip \ + bash-completion \ + build-essential \ + ninja-build \ + htop \ + iputils-ping \ + jq \ + less \ + locales \ + man-db \ + nano \ + ripgrep \ + software-properties-common \ + sudo \ + stow \ + time \ + emacs-nox \ + vim \ + multitail \ + lsof \ + ssl-cert \ + fish \ + zsh \ + yadm \ + && locale-gen en_US.UTF-8 \ + && upgrade-packages + +ENV LANG=en_US.UTF-8 + +COPY sources.list.d/ /etc/apt/sources.list.d/ + +# Seperate the install via apt part since we dump the *.sources file first +# and we need the dearmored keys to work. +RUN curl -fsSL "https://keyserver.ubuntu.com/pks/lookup?op=get&search=0xf911ab184317630c59970973e363c90f8f1b6217" > /tmp/key.gpg \ + && gpg --dearmor - < /tmp/key.gpg > /usr/share/keyrings/git-ppa-archive-keyring.gpg \ + && curl -fsSL https://packagecloud.io/github/git-lfs/gpgkey > /tmp/key.gpg \ + && gpg --dearmor - < /tmp/key.gpg > /usr/share/keyrings/github_git-lfs.gpg \ + && curl -fsSL https://pkgs.tailscale.com/stable/ubuntu/jammy.gpg > /tmp/key.gpg \ + && gpg --dearmor - < /tmp/key.gpg > /usr/share/keyrings/tailscale-archive-keyring.gpg \ + && rm /tmp/key.gpg + +RUN install-packages git git-lfs git-email \ + && git lfs install --system --skip-repo + +RUN install-packages tailscale \ + && update-alternatives --set ip6tables /usr/sbin/ip6tables-nft + +# Setup both devenv user and Gitpod compat user for use in Gitpod. +RUN userdel ubuntu -f -r && \ + useradd -l -u 33333 -G sudo -md /home/gitpod -s /bin/bash -p gitpod gitpod \ + && useradd -l -u 1000 -G sudo,gitpod -md /home/user -s /bin/bash -p devenv user \ + # Remove `use_pty` option and enable passwordless sudo. + && sed -i.bkp -e '/Defaults\tuse_pty/d' -e 's/%sudo\s\+ALL=(ALL\(:ALL\)\?)\s\+ALL/%sudo ALL=NOPASSWD:ALL/g' /etc/sudoers \ + && mkdir /workspace && chown -hR gitpod:gitpod /workspace + +USER user +WORKDIR /home/user +ARG dotfiles=https://mau.dev/andreijiroh-dev/dotfiles +ARG dotfilesBranch=main +RUN yadm clone ${dotfiles} && yadm restore --staged $HOME && yadm checkout ${dotfilesBranch} -- $HOME \ No newline at end of file diff --git a/docker/devenv/base/sources.list.d/git.sources b/docker/devenv/base/sources.list.d/git.sources new file mode 100644 index 0000000..c3a7e22 --- /dev/null +++ b/docker/devenv/base/sources.list.d/git.sources @@ -0,0 +1,11 @@ +Types: deb +URIs: https://ppa.launchpadcontent.net/git-core/ppa/ubuntu +Suites: noble +Components: main +Signed-By: /usr/share/keyrings/git-ppa-archive-keyring.gpg + +Types: deb +URIs: https://packagecloud.io/github/git-lfs/ubuntu +Suites: noble +Components: main +Signed-By: /usr/share/keyrings/github_git-lfs.gpg \ No newline at end of file diff --git a/docker/devenv/base/sources.list.d/tailscale.sources b/docker/devenv/base/sources.list.d/tailscale.sources new file mode 100644 index 0000000..d5cb68b --- /dev/null +++ b/docker/devenv/base/sources.list.d/tailscale.sources @@ -0,0 +1,5 @@ +Types: deb +URIs: https://pkgs.tailscale.com/unstable/ubuntu +Suites: jammy +Components: main +Signed-By: /usr/share/keyrings/tailscale-archive-keyring.gpg \ No newline at end of file diff --git a/docker/devenv/ci/Dockerfile b/docker/devenv/ci/Dockerfile new file mode 100644 index 0000000..5ff45ef --- /dev/null +++ b/docker/devenv/ci/Dockerfile @@ -0,0 +1,2 @@ +ARG base=dock.mau.dev/andreijiroh-dev/docker-images/devenv/base +FROM ${base} diff --git a/docker/devenv/cloudshell/.cloudshellcustomimagerepo.json b/docker/devenv/cloudshell/.cloudshellcustomimagerepo.json new file mode 100644 index 0000000..6e457a6 --- /dev/null +++ b/docker/devenv/cloudshell/.cloudshellcustomimagerepo.json @@ -0,0 +1,4 @@ +{ + "projectId": "ajhalili2006", + "repoId": "devenv/cloudshell" +} \ No newline at end of file diff --git a/docker/devenv/cloudshell/Dockerfile b/docker/devenv/cloudshell/Dockerfile new file mode 100644 index 0000000..d9350fc --- /dev/null +++ b/docker/devenv/cloudshell/Dockerfile @@ -0,0 +1,20 @@ +FROM gcr.io/cloudshell-images/cloudshell:latest + +# Load up our repo lists and GPG keys +COPY sources.list.d/ /etc/apt/sources.list.d +RUN curl -fsSL https://packagecloud.io/github/git-lfs/gpgkey > /tmp/key.gpg \ + && gpg --dearmor - < /tmp/key.gpg > /usr/share/keyrings/github_git-lfs.gpg \ + && curl -fsSL https://pkgs.tailscale.com/stable/ubuntu/jammy.gpg > /tmp/key.gpg \ + && gpg --dearmor - < /tmp/key.gpg > /usr/share/keyrings/tailscale-archive-keyring.gpg \ + && rm /tmp/key.gpg \ + && curl -sSLo /tmp/debsuryorg-archive-keyring.deb https://packages.sury.org/debsuryorg-archive-keyring.deb \ + && curl -sSLo /tmp/mysql-apt-config.deb https://dev.mysql.com/get/mysql-apt-config_0.8.32-1_all.deb \ + && dpkg -i /tmp/debsuryorg-archive-keyring.deb && dpkg -i /tmp/mysql-apt-config.deb && rm /tmp/*.deb + +# Do install and cleanup in one-step +RUN apt-get update --allow-releaseinfo-change && \ + apt-get upgrade -y \ + && apt-get install -y git-lfs tailscale \ + && apt-get clean \ + && curl -fsSL https://getcroc.schollz.com | bash \ + && rm -rf /var/cache/debconf/* /var/lib/apt/lists/* /tmp/* /var/tmp/* \ No newline at end of file diff --git a/docker/devenv/cloudshell/sources.list.d/git.sources b/docker/devenv/cloudshell/sources.list.d/git.sources new file mode 100644 index 0000000..425a1ed --- /dev/null +++ b/docker/devenv/cloudshell/sources.list.d/git.sources @@ -0,0 +1,5 @@ +Types: deb +URIs: https://packagecloud.io/github/git-lfs/debian +Suites: bullseye +Components: main +Signed-By: /usr/share/keyrings/github_git-lfs.gpg \ No newline at end of file diff --git a/docker/devenv/cloudshell/sources.list.d/tailscale.sources b/docker/devenv/cloudshell/sources.list.d/tailscale.sources new file mode 100644 index 0000000..b0b84c0 --- /dev/null +++ b/docker/devenv/cloudshell/sources.list.d/tailscale.sources @@ -0,0 +1,5 @@ +Types: deb +URIs: https://pkgs.tailscale.com/unstable/debian +Suites: bullseye +Components: main +Signed-By: /usr/share/keyrings/tailscale-archive-keyring.gpg \ No newline at end of file diff --git a/docker/devenv/gitpod/Dockerfile b/docker/devenv/gitpod/Dockerfile new file mode 100644 index 0000000..abb55b0 --- /dev/null +++ b/docker/devenv/gitpod/Dockerfile @@ -0,0 +1,4 @@ +ARG base=dock.mau.dev/andreijiroh-dev/docker-images/devenv/base +FROM ${base} + +USER gitpod \ No newline at end of file diff --git a/scripts/build b/scripts/build new file mode 100755 index 0000000..e465fd3 --- /dev/null +++ b/scripts/build @@ -0,0 +1,27 @@ +#!/usr/bin/env bash +set -e + +if [[ $DEBUG != "" ]]; then + set -x +fi + +main() { + DOCKER_BUILD_ARGS=${DOCKER_BUILD_ARGS:-} + GIT_ROOT_TMP=$(git rev-parse --show-toplevel) + GIT_ROOT=${GIT_ROOT:-"$GIT_ROOT_TMP"} + DOCKER_BUILDKIT=${DOCKER_BUILDKIT:-"1"} + BUILD_DIR="docker/${1}" + DOCKER_IMAGE_NAME=${2:-"dock.mau.dev/andreijiroh-dev/docker-images/${1}"} + + if [[ ! -d "${GIT_ROOT}/${BUILD_DIR}" ]]; then + echo "error: ${BUILD_DIR} does not exist here" + return 1 + fi + + docker build -f "${GIT_ROOT}/${BUILD_DIR}/Dockerfile" \ + -t "${DOCKER_IMAGE_NAME}:localdev" \ + ${DOCKER_BUILD_ARGS} \ + "${GIT_ROOT}/${BUILD_DIR}" +} + +main "$*" \ No newline at end of file