This commit is contained in:
Tomas Mirchev 2024-09-14 19:18:14 +02:00
parent ea739e5509
commit 22e844e7e5
4 changed files with 53 additions and 45 deletions

View File

@ -19,20 +19,16 @@ RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
&& apt-get clean -y \
&& rm -rf /var/lib/apt/lists/*
RUN groupadd -g 1001 dev
RUN useradd -u 1001 -g 1001 -m -s /bin/zsh dev
RUN useradd -m -s /bin/zsh dev
RUN echo "dev ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
RUN mkdir /workspace
RUN mkdir /workspace && chown dev:dev /workspace
WORKDIR /workspace
VOLUME ["/workspace"]
ENV w=/workspace
RUN chown -R dev:dev /workspace
COPY create-zshenv.sh /usr/local/bin/create-zshenv.sh
RUN chmod +x /usr/local/bin/create-zshenv.sh
RUN /usr/local/bin/create-zshenv.sh
COPY install-tools.sh /usr/local/bin/install-tools.sh
RUN chmod +x /usr/local/bin/install-tools.sh
USER dev
RUN /usr/local/bin/install-tools.sh
CMD ["zsh"]

View File

@ -1,3 +1,23 @@
docker build -t my-dev-container .
docker run -it --rm -v ~/apps/gateway:/usr/src/app -w /usr/src/app my-dev-container
# Dev containers
## Commands
Build
```
podman build -t my-dev-container .
```
Run. Mount /workspace if you want to preserve changes. Mount /workspace if you want to preserve changes.
```
podman run -it --rm \
--userns=keep-id \
--network host \
-v $HOME/.ssh:/home/dev/.ssh:ro,Z \
-v $PWD:/workspace:Z \
my-dev-container
```
## Installed tools
- Common ones: curl, git, vim, tmux, zsh. Included dotfiles.
- NVM and nodejs (lts, v18, v20, v22).
- All package managers preinstalled (npm, pnpm, yarn). Enable with `corepack enable <pm>`.

View File

@ -1,33 +0,0 @@
#!/bin/sh
# Create the file as root
cat << 'EOF' > /home/dev/.zshenv
# ~/.zshenv
export HOME="/home/dev"
export XDG_CONFIG_HOME="$HOME/.config"
export ZDOTDIR="$XDG_CONFIG_HOME/zsh"
export TMUX_CONFIG_HOME="$XDG_CONFIG_HOME/tmux"
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
EOF
# Change ownership to dev user
chown dev:dev /home/dev/.zshenv
su - dev -c /bin/bash << 'EOF'
export NVM_DIR="$HOME/.nvm"
mkdir -p "$NVM_DIR"
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash
. "$NVM_DIR/nvm.sh"
nvm install --lts
nvm install 18
nvm install 20
nvm install 22
corepack prepare npm --activate
corepack prepare yarn --activate
corepack prepare pnpm --activate
corepack disable
EOF

View File

@ -0,0 +1,25 @@
#!/bin/sh
set -e
# Install dotfiles
git clone https://gitea.tomastm.com/tomas.mirchev/dotfiles.git $HOME/.dotfiles
python3 $HOME/.dotfiles/install.py -e linux-dev
# Install NVM
export NVM_DIR="$HOME/.nvm"
mkdir -p "$NVM_DIR"
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash
. "$NVM_DIR/nvm.sh"
# Preinstall a few nodejs versions
nvm install --lts # The first version installed becomes the default
nvm install 18
nvm install 20
nvm install 22
# Preinstall all package managers
corepack prepare npm --activate
corepack prepare yarn --activate
corepack prepare pnpm --activate
corepack disable