Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Archlinux gitpod layer #4900

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
# Copyright (c) 2020 Gitpod GmbH. All rights reserved.
# Licensed under the GNU Affero General Public License (AGPL).
# See License-AGPL.txt in the project root for license information.

# 'FROM ${BASE_IMAGE}' prepended here

###############################################################################
# REQUIRED
###############################################################################
# !!! We expect users to configure their containers as root !!!
USER root

# ─── INITIAL SETUP ──────────────────────────────────────────────────────────────
USER root
RUN \
pacman-key --init > /dev/null 2>&1 \
&& pacman-key --populate archlinux > /dev/null 2>&1 \
&& pacman -Syyu --noconfirm >/dev/null 2>&1 \
&& pacman -S --noconfirm bash >/dev/null 2>&1
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
# ─── INITIAL VALIDATIONS ────────────────────────────────────────────────────────
USER root
# [ NOTE ] in case gitpod user exists and has a uid
# that is not 33333, this run statement will fail.
RUN \
set -xue ; \
if getent passwd "gitpod" > /dev/null 2>&1; then \
[ "$(id -u gitpod)" != "33333" ] \
&& echo >&2 "Error: User 'gitpod' exists but does not have user-id 33333. The user-id is $(id -u)" \
&& exit 1 ; \
else \
exit 0 ; \
fi
# ─── CONFIGURING PACMAN ─────────────────────────────────────────────────────────
USER root
RUN \
set -xue ; \
sed -i \
-e "/ParallelDownloads/d" \
-e '/\[options\]/a ParallelDownloads = 16' \
/etc/pacman.conf \
&& sed -i \
-e "/Color/d" \
-e "/ILoveCandy/d" \
-e '/\[options\]/a Color' \
-e '/\[options\]/a ILoveCandy' \
/etc/pacman.conf ;
# ─── INSTALLING CORE PACKAGES ───────────────────────────────────────────────────
USER root
RUN \
set -xue ; \
[ -r /usr/bin/gp ] && ln -sf /usr/bin/gp /usr/bin/gp-preview ; \
pacman -Sy --noconfirm --needed \
git \
base-devel \
bash-completion \
wget \
curl \
sudo \
> /dev/null 2>&1 ;
# ─── SUDO SETUP ─────────────────────────────────────────────────────────────────
USER root
RUN \
set -xue ; \
! getent group sudo > /dev/null && groupadd sudo \
&& sed -i \
-e '/%wheel.*NOPASSWD:\s*ALL/d' \
-e '/%wheel\s\+ALL=(ALL\(:ALL\)\?)\s\+ALL/d' \
/etc/sudoers \
&& ( \
echo "%wheel ALL=(ALL) ALL" ; \
echo "%wheel ALL=(ALL) NOPASSWD: ALL" ; \
) | tee -a /etc/sudoers > /dev/null ;
# ─── USER SETUP ─────────────────────────────────────────────────────────────────
USER root
# [ NOTE ] => user password was generated through the following command
# perl -e 'print crypt($ARGV[0], "password")' "gitpod"
RUN \
set -xue ; \
! getent group "gitpod" > /dev/null \
&& groupadd --gid "33333" "gitpod" > /dev/null > /dev/null ; \
! getent passwd "gitpod" > /dev/null \
&& useradd \
--no-log-init \
--create-home \
--home-dir "/home/gitpod" \
--gid "33333" \
--uid "33333" \
--groups sudo \
--shell "/bin/bash" \
--password "paF0XkFNewMcY" \
"gitpod" && \
cp -R /root/. /home/gitpod ;
RUN \
set -xue ; \
echo "gitpod:gitpod" | chpasswd \
&& chown "$(id -u gitpod):$(id -g gitpod)" /home/gitpod/ -R \
&& usermod -aG wheel,root "gitpod" \
&& passwd -l root || true
# ─── PARU INSTALL ───────────────────────────────────────────────────────────────
USER "gitpod"
# [ NOTE ] => this run statement tries to install paru up to five failures
# as sometimes, aur may be temporarily unavailable
RUN \
set -xue ; \
[ ! -d "/home/gitpod/.cargo" ] && clean_cargo="true" || clean_cargo=="false" ; \
git clone https://aur.archlinux.org/paru.git /tmp/paru \
&& pushd /tmp/paru > /dev/null 2>&1 \
&& for i in {1..5}; do makepkg --noconfirm -sicr > /dev/null 2>&1 && break || sleep 15; done \
&& paru --version > /dev/null 2>&1 \
! cargo --version > /dev/null 2>&1 \
&& popd > /dev/null 2>&1 \
&& [[ "${clean_cargo}" == "true" ]] && rm -r "/home/gitpod/.cargo" ;
# ─── COPY CONFIG AND LAYER SCRIPT ───────────────────────────────────────────────
COPY ./gitpod /var/gitpod
# ─── CONFIGURE USER SHELL ───────────────────────────────────────────────────────
USER "gitpod"
# TODO Remove this in the near future when we do not need ~/.bashrc appends/prepends any more
RUN \
set -xue ; \
BASH_RC=~/.bashrc; \
[ ! -d "/home/gitpod" ] && echo >&2 "'gitpod' user home directory not found" && exit 1 ; \
[ -r "$BASH_RC" ] && cp "$BASH_RC" ~/.bashrc-org || touch ~/.bashrc-org ; \
touch ~/.hushlogin ; \
cat /var/gitpod/.bashrc-prepend > "$BASH_RC" \
&& cat ~/.bashrc-org >> "$BASH_RC" \
&& cat /var/gitpod/.bashrc-append >> "$BASH_RC"
# ─── CLEANUP AND FINALIZATIONS ──────────────────────────────────────────────────
USER root
RUN \
set -xue ; \
chown "$(id -u gitpod):$(id -g gitpod)" "/home/gitpod" -R \
&& pacman -Qdtq | sudo pacman -Rs - > /dev/null 2>&1 || true \
&& pacman --noconfirm -Scc > /dev/null 2>&1 \
&& rm -rf \
/var/cache/pacman/pkg/* \
/tmp/*
# ────────────────────────────────────────────────────────────────────────────────
USER gitpod
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@


###############################################################################
########## Gitpod - append - begin
###############################################################################


###############################################################################
########## Gitpod - append - end
###############################################################################

Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@


###############################################################################
########## Gitpod - prepend
###############################################################################

# Prompt color and bash_completion
export PS1='[\u@\h \W]\$ '
#source /etc/bash_completion

# editor config - should be removed when registry facade is default
if [ -z "$EDITOR" ]; then
export EDITOR="gp open -w"
fi
if [ -z "$VISUAL" ]; then
export VISUAL="$EDITOR"
fi
if [ -z "$GIT_EDITOR" ]; then
export GIT_EDITOR="$EDITOR"
fi

# Workaround Java pre v10 by explicitly setting "-Xmx" for all Hotspot/openJDK VMs
if [ -n "$GITPOD_MEMORY" ]; then
export JAVA_TOOL_OPTIONS="-Xmx${GITPOD_MEMORY}m";
fi

# Completion for gp command
command -- gp -h >/dev/null 2>&1 && . <(gp completion)
# ide cli config - should be removed when registry facade is default
if [ ! -d "/ide/bin/" ]; then
alias open='gp open'
alias code='gp open'
fi

export GEM_HOME=/workspace/.rvm
export GEM_PATH=$GEM_HOME:$GEM_PATH
export PATH=/workspace/.rvm/bin:$PATH

export PIPENV_VENV_IN_PROJECT=true
export PIP_USER=yes
export PYTHONUSERBASE=/workspace/.pip-modules
export PATH=$PYTHONUSERBASE/bin:$PATH
unset PIP_TARGET
unset PYTHONPATH

# Set CARGO_HOME to reside in workspace if:
# - it's RUNTIME (/workspace present)
if [ -d /workspace ]; then
export CARGO_HOME=/workspace/.cargo
export PATH=$CARGO_HOME/bin:$PATH
fi

export BROWSER="${BROWSER:=gp-preview}"

###############################################################################
########## Gitpod - prepend
###############################################################################

Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# - /etc/os-release to contain the distro 'ID='
# Postconditions:
# - stores result in file '/workspace/distro'
# - valid values: debian | alpine | "amzn" | UNDEFINED
# - valid values: debian | alpine | "amzn" | archlinux | UNDEFINED

if [ ! -f /etc/os-release ]; then
DISTRO="UNDEFINED"
Expand All @@ -37,12 +37,13 @@ case "$DISTRO" in
"alpine")
DISTRO="alpine"
;;

"arch")
DISTRO="archlinux"
;;
*)
DISTRO="UNDEFINED"
;;
esac

OUT_FILE="/workspace/distro"
printf '%s\n' "$DISTRO" > "$OUT_FILE"
printf '%s\n' "Found distro: $DISTRO. Wrote file $OUT_FILE."
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
FROM archlinux:base
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
FROM archlinux:base
RUN \
pacman-key --init \
&& pacman-key --populate archlinux \
&& pacman -Syyu --noconfirm \
&& pacman -S --noconfirm bash sudo
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
RUN \
set -xue ; \
! getent group sudo > /dev/null && groupadd sudo ; \
groupadd --gid "33333" "gitpod" > /dev/null > /dev/null \
&& useradd \
--no-log-init \
--create-home \
--home-dir "/home/gitpod" \
--groups sudo \
--gid "33333" \
--uid "33333" \
--shell "/bin/bash" \
"gitpod"
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
FROM archlinux:base
RUN \
pacman-key --init \
&& pacman-key --populate archlinux \
&& pacman -Syyu --noconfirm \
&& pacman -S --noconfirm bash
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
RUN \
set -xue ; \
groupadd --gid "33333" "gitpod" > /dev/null > /dev/null \
&& useradd \
--no-log-init \
--create-home \
--home-dir "/home/gitpod" \
--gid "33333" \
--uid "33333" \
--shell "/bin/bash" \
"gitpod"
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM archlinux:base
RUN \
pacman-key --init \
&& pacman-key --populate archlinux \
&& pacman -Syyu --noconfirm \
&& pacman -S --noconfirm bash