Skip to content

Commit

Permalink
Consolidate and update vscode/dev-container config
Browse files Browse the repository at this point in the history
  • Loading branch information
marko-k0 authored and Enzo Desiage committed Jun 27, 2023
1 parent 94a946d commit 5834d41
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 20 deletions.
29 changes: 19 additions & 10 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
{
"image": "dfinity/ic-build:6cef3a74a91521a4ded657aa62af44388d1841f8d69b06fb0129caedf99fb2c8",
"image": "dfinity/ic-build:93840650a4491db0e9917f901a30522cff963b20c21804b2368616c03db089c5",
"remoteUser": "ubuntu",
"privileged": true,
"runArgs": [
"--hostname",
"devenv-container"
"devenv-container",
"--network",
"host",
"--cgroupns",
"host",
"--add-host",
"devenv-container:127.0.0.1"
],
"workspaceMount": "source=${localWorkspaceFolder},target=/ic,type=bind",
"workspaceFolder": "/ic",
"initializeCommand": "mkdir -p ~/.{aws,ssh,cache,local/share/fish} && touch ~/.{zsh,bash}_history",
"mounts": [
{
"source": "${localEnv:HOME}/.cache",
Expand All @@ -24,13 +32,18 @@
"type": "bind"
},
{
"source": "${localEnv:HOME}/.config",
"target": "/home/ubuntu/.config",
"source": "${localEnv:HOME}/.bash_history",
"target": "/home/ubuntu/.bash_history",
"type": "bind"
},
{
"source": "${localEnv:HOME}/.local",
"target": "/home/ubuntu/.local",
"source": "${localEnv:HOME}/.zsh_history",
"target": "/home/ubuntu/.zsh_history",
"type": "bind"
},
{
"source": "${localEnv:HOME}/.local/share/fish",
"target": "/home/ubuntu/.local/share/fish",
"type": "bind"
},
{
Expand All @@ -43,10 +56,6 @@
"SSH_AUTH_SOCK": "${localEnv:SSH_AUTH_SOCK}",
"TERM": "xterm-256color"
},
"remoteEnv": {
"PATH": "${containerEnv:PATH}:/ic/bin",
"PYTHONPATH": "${containerEnv:PYTHONPATH}:/ic/gitlab-ci/src:/ic/gitlab-ci/src/dependencies"
},
"customizations": {
"vscode": {
"extensions": [
Expand Down
4 changes: 2 additions & 2 deletions gitlab-ci/config/00--common--images.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
artifacts:
expire_in: 3 days
image:
name: "registry.gitlab.com/dfinity-lab/core/docker/ic-build:6cef3a74a91521a4ded657aa62af44388d1841f8d69b06fb0129caedf99fb2c8"
name: "registry.gitlab.com/dfinity-lab/core/docker/ic-build:93840650a4491db0e9917f901a30522cff963b20c21804b2368616c03db089c5"
tags:
- dfinity-ic
variables:
Expand All @@ -14,7 +14,7 @@
artifacts:
expire_in: 3 days
image:
name: "registry.gitlab.com/dfinity-lab/core/docker/ic-build-legacy:6cef3a74a91521a4ded657aa62af44388d1841f8d69b06fb0129caedf99fb2c8"
name: "registry.gitlab.com/dfinity-lab/core/docker/ic-build-legacy:93840650a4491db0e9917f901a30522cff963b20c21804b2368616c03db089c5"
tags:
- dfinity-ic
variables:
Expand Down
5 changes: 4 additions & 1 deletion gitlab-ci/container/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ COPY --chown=0700 ./gitlab-ci/container/files/known_hosts /etc/ssh/ssh_known_hos

RUN export DEBIAN_FRONTEND=noninteractive && ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone && \
apt -yq update && apt -yqq install \
curl build-essential git gnupg node-json5 uuid-dev zsh clang iproute2 shellcheck \
curl build-essential git gnupg node-json5 uuid-dev zsh fish clang iproute2 shellcheck \
# GitLab CI \
sudo gosu jq rclone time qemu-system-x86 \
# Test \
Expand Down Expand Up @@ -84,6 +84,9 @@ ARG BUF_VERSION="1.21.0"
RUN curl -sSL "https://github.com/bufbuild/buf/releases/download/v${BUF_VERSION}/buf-$(uname -s)-$(uname -m)" \
-o "${BUF_BIN}/buf" && chmod +x "${BUF_BIN}/buf"

# Add zshrc generated from zsh-newuser-install (option 2)
COPY --chown=ubuntu:ubuntu ./gitlab-ci/container/files/zshrc /home/ubuntu/.zshrc

# Add yq
ARG YQ_BIN="/usr/local/bin/yq"
ARG YQ_VERSION="4.34.1"
Expand Down
7 changes: 5 additions & 2 deletions gitlab-ci/container/Dockerfile.legacy
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone &
zip unzip rclone rsync bc csmith gcc lld lld-10 libc++-10-dev libcsmith-dev sqlite3 libsqlite3-dev libselinux-dev libunwind-dev libsystemd-dev uuid-dev \
qemu-system-x86 ovmf iproute2 dosfstools mtools fakeroot faketime android-sdk-ext4-utils \
policycoreutils python-is-python3 python3 python3-pip python3-cbor shellcheck \
sudo docker-ce-cli ripgrep patchelf cpio nodejs npm gosu pigz zsh hub less \
sudo docker-ce-cli ripgrep patchelf cpio nodejs npm gosu pigz zsh fish hub less \
ca-certificates curl git isolinux p7zip-full syslinux xorriso cryptsetup-bin autoconf automake \
grub-efi-amd64-bin podman buildah lvm2 fuse-overlayfs google-cloud-cli

COPY --from=docker/buildx-bin:latest /buildx /usr/libexec/docker/cli-plugins/docker-buildx
COPY --from=docker.io/docker/buildx-bin:latest /buildx /usr/libexec/docker/cli-plugins/docker-buildx

# Add the `${USER}` user, and the required folders
ARG USER=ubuntu
Expand Down Expand Up @@ -124,6 +124,9 @@ COPY ./gitlab-ci/container/files/known_hosts /home/${USER}/.ssh/known_hosts
COPY ./gitlab-ci/container/files/entrypoint.sh /entrypoint.sh
WORKDIR /

# Add zshrc generated from zsh-newuser-install (option 2)
COPY --chown=ubuntu:ubuntu ./gitlab-ci/container/files/zshrc /home/ubuntu/.zshrc

USER 0

RUN mv /usr/bin/docker /usr/bin/docker-bin
Expand Down
2 changes: 1 addition & 1 deletion gitlab-ci/container/TAG
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6cef3a74a91521a4ded657aa62af44388d1841f8d69b06fb0129caedf99fb2c8
93840650a4491db0e9917f901a30522cff963b20c21804b2368616c03db089c5
32 changes: 28 additions & 4 deletions gitlab-ci/container/container-run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,8 @@ PODMAN_RUN_ARGS=(
-w "$WORKDIR"

-u "$(id -u):$(id -g)"
-e HOME="/home/$USER"
-e VERSION="${VERSION:-$(git rev-parse HEAD)}"
-e HOSTUSER="$USER"
-e VERSION="${VERSION:-$(git rev-parse HEAD)}"
--hostname=devenv-container
--add-host devenv-container:127.0.0.1
--entrypoint=
Expand All @@ -88,11 +87,29 @@ fi

PODMAN_RUN_ARGS+=(
--mount type=bind,source="${REPO_ROOT}",target="${WORKDIR}"
--mount type=bind,source="/var/lib/containers",target="/var/lib/containers"
--mount type=bind,source="${HOME}",target="${HOME}"
--mount type=bind,source="${HOME}/.cache",target="/home/ubuntu/.cache"
--mount type=bind,source="${HOME}/.ssh",target="/home/ubuntu/.ssh"
--mount type=bind,source="${HOME}/.aws",target="/home/ubuntu/.aws"
--mount type=tmpfs,destination=/var/sysimage
)

if [ -e "${HOME}/.bash_history" ]; then
PODMAN_RUN_ARGS+=(
--mount type=bind,source="${HOME}/.bash_history",target="/home/ubuntu/.bash_history"
)
fi
if [ -e "${HOME}/.local/share/fish" ]; then
PODMAN_RUN_ARGS+=(
--mount type=bind,source="${HOME}/.local/share/fish",target="/home/ubuntu/.local/share/fish"
)
fi
if [ -e "${HOME}/.zsh_history" ]; then
PODMAN_RUN_ARGS+=(
--mount type=bind,source="${HOME}/.zsh_history",target="/home/ubuntu/.zsh_history"
)
fi

if [ -n "${SSH_AUTH_SOCK:-}" ] && [ -e "${SSH_AUTH_SOCK:-}" ]; then
PODMAN_RUN_ARGS+=(
-v "$SSH_AUTH_SOCK:/ssh-agent"
Expand All @@ -102,12 +119,19 @@ else
echo "No ssh-agent to forward."
fi

# make sure we have all bind-mounts
mkdir -p ~/.{aws,ssh,cache,local/share/fish} && touch ~/.{zsh,bash}_history

# privileged rootful podman is required due to requirements of IC-OS guest build
# additionally, we need to use hosts's cgroups and network
if [ $# -eq 0 ]; then
SHELL=$(getent passwd "$USER" | cut -d : -f 7)
if [[ "$SHELL" != *"/bash" ]] && [[ "$SHELL" != *"/zsh" ]] && [[ "$SHELL" != *"/fish" ]]; then
SHELL=/usr/bin/bash
fi
set -x
sudo podman run --pids-limit=-1 -it --rm --privileged --network=host --cgroupns=host \
"${PODMAN_RUN_ARGS[@]}" -w "$WORKDIR" "$IMAGE" bash --rcfile /etc/bash.bashrc --rcfile /home/ubuntu/.bashrc
"${PODMAN_RUN_ARGS[@]}" -w "$WORKDIR" "$IMAGE" $SHELL
set +x
else
set -x
Expand Down
36 changes: 36 additions & 0 deletions gitlab-ci/container/files/zshrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Content generated from zsh-newuser-install (option 2).

autoload -Uz promptinit
promptinit
prompt adam1

setopt histignorealldups sharehistory

# Use emacs keybindings even if our EDITOR is set to vi
bindkey -e

# Keep 1000 lines of history within the shell and save it to ~/.zsh_history:
HISTSIZE=10000
HISTFILE=~/.zsh_history

# Use modern completion system
autoload -Uz compinit
compinit

zstyle ':completion:*' auto-description 'specify: %d'
zstyle ':completion:*' completer _expand _complete _correct _approximate
zstyle ':completion:*' format 'Completing %d'
zstyle ':completion:*' group-name ''
zstyle ':completion:*' menu select=2
eval "$(dircolors -b)"
zstyle ':completion:*:default' list-colors ${(s.:.)LS_COLORS}
zstyle ':completion:*' list-colors ''
zstyle ':completion:*' list-prompt %SAt %p: Hit TAB for more, or the character to insert%s
zstyle ':completion:*' matcher-list '' 'm:{a-z}={A-Z}' 'm:{a-zA-Z}={A-Za-z}' 'r:|[._-]=* r:|=* l:|=*'
zstyle ':completion:*' menu select=long
zstyle ':completion:*' select-prompt %SScrolling active: current selection at %p%s
zstyle ':completion:*' use-compctl false
zstyle ':completion:*' verbose true

zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#)*=0=01;31'
zstyle ':completion:*:kill:*' command 'ps -u $USER -o pid,%cpu,tty,cputime,cmd'

0 comments on commit 5834d41

Please sign in to comment.