Skip to content

Commit

Permalink
chore: docker setup
Browse files Browse the repository at this point in the history
  • Loading branch information
pragmaticivan committed Jul 4, 2024
1 parent 8d41e45 commit 3853263
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 32 deletions.
62 changes: 41 additions & 21 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,32 +1,52 @@
FROM ubuntu:22.04
ARG BASE_IMAGE=ubuntu:22.04

# ========================================
# Base environment
# ========================================

FROM ${BASE_IMAGE} as base

# Avoid the following error:
# curl: (77) error setting certificate file: /etc/ssl/certs/ca-certificates.crt
RUN apt-get update && apt-get install -y --no-install-recommends \
ca-certificates

# Install minimum requirements
RUN apt-get install -y --no-install-recommends \
sudo \
git \
wget \
curl

ARG USERNAME=pragmaticivan
ARG USER_UID=1000
ARG USER_GID=$USER_UID
ARG USER_GID=${USER_UID}

<<<<<<< Updated upstream
ENV TZ=America/Chicago
=======
<<<<<<< Updated upstream
ENV TZ=Asia/Tokyo
>>>>>>> Stashed changes
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
=======
RUN groupadd --gid ${USER_GID} ${USERNAME} \
&& useradd --uid ${USER_UID} --gid ${USER_GID} -m ${USERNAME} -G sudo -s /bin/bash \
&& echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers \
&& echo 'Defaults verifypw = any' >> /etc/sudoers
USER ${USERNAME}
>>>>>>> Stashed changes

RUN apt-get update && \
apt-get install -y --no-install-recommends \
curl \
git \
bats \
kcov \
sudo \
tzdata \
parallel \
build-essential \
ca-certificates
WORKDIR /home/${USERNAME}

RUN groupadd --gid $USER_GID $USERNAME \
&& useradd --uid $USER_UID --gid $USER_GID -m $USERNAME -G sudo -s /bin/bash \
&& echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers

USER $USERNAME
WORKDIR /home/$USERNAME/.local/share/chezmoi
FROM base as dev

# Install chezmoi
RUN sudo sh -c "$(curl -fsLS get.chezmoi.io)" -- -b /usr/local/bin

RUN mkdir -p ~/.local/share/fonts
RUN mkdir -p /tmp
# Install requirements for testing
RUN sudo apt-get install -y --no-install-recommends \
bats \
kcov

WORKDIR /home/${USERNAME}/.local/share/chezmoi
38 changes: 27 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,19 +1,35 @@
DOCKER_IMAGE_NAME=dotfiles
DOCKER_ARCH=x86_64
DOCKER_NUM_CPU=4
DOKCER_RAM_GB=4

DOCKER_PLATFORM=linux/amd64
#
# Docker
#

.PHONY: docker
docker:
@if ! docker inspect $(DOCKER_IMAGE_NAME) &>/dev/null; then \
docker build -t $(DOCKER_IMAGE_NAME) . --build-arg USERNAME="$$(whoami)"; \
fi
docker run -it -v "$$(pwd):/home/$$(whoami)/.local/share/chezmoi" dotfiles /bin/bash --login

.PHONY: docker-build-base
docker-build-base:
docker build -t $(DOCKER_IMAGE_NAME) \
--target base \
--platform $(DOCKER_PLATFORM) . \
--build-arg USERNAME="$$(whoami)"

.PHONY: docker-run-base
docker-run-base: docker-build-base
docker run --rm -it \
--platform $(DOCKER_PLATFORM) $(DOCKER_IMAGE_NAME) \
/bin/bash --login

.PHONY: docker-build-dev
docker-build-dev:
docker build -t $(DOCKER_IMAGE_NAME) \
--target dev \
--platform $(DOCKER_PLATFORM) . \
--build-arg USERNAME="$$(whoami)"

.PHONY: docker-run-dev
docker-run-dev: docker-build-dev
docker run --rm -it \
-v "$$(pwd):/home/$$(whoami)/.local/share/chezmoi" \
--platform $(DOCKER_PLATFORM) $(DOCKER_IMAGE_NAME) \
/bin/bash --login
#
# Chezmoi
#
Expand Down

0 comments on commit 3853263

Please sign in to comment.