Skip to content

Commit

Permalink
Merge pull request #2224 from replicatedhq/codespaces-sandbox
Browse files Browse the repository at this point in the history
optimize build
  • Loading branch information
Dan Stough committed Oct 1, 2021
2 parents ee5f65e + 98acd1f commit b1f6ba8
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 43 deletions.
10 changes: 8 additions & 2 deletions .devcontainer/Dockerfile
Expand Up @@ -101,9 +101,15 @@ RUN bash /tmp/scripts/replicated-debian.sh \
&& rm -rf /tmp/scripts \
&& apt-get clean -y

# Userspace
ENV SHELL=/bin/zsh
USER ${USERNAME}
COPY --chown=${USERNAME}:root library-scripts/replicated-userspace.sh /tmp/scripts/
RUN bash /usr/local/share/docker-init.sh \
&& bash /tmp/scripts/replicated-userspace.sh \
&& rm -rf /tmp/scripts/scripts

# Fire Docker/Moby script if needed along with Oryx's benv
ENTRYPOINT [ "/usr/local/share/docker-init.sh", "/usr/local/share/ssh-init.sh", "benv" ]
CMD [ "sleep", "infinity" ]

ENV SHELL=/bin/zsh
USER ${USERNAME}
7 changes: 5 additions & 2 deletions .devcontainer/config/k3d-cluster.yaml
@@ -1,7 +1,10 @@
apiVersion: k3d.io/v1alpha2
apiVersion: k3d.io/v1alpha3
kind: Simple
name: replicated
servers: 1
image: rancher/k3s:v1.21.4-k3s1 # v1.21.3-k3s1 default is broken
registries:
create: true
create:
name: k3d-replicated-registry.localhost
host: "0.0.0.0"
hostPort: "5000"
2 changes: 2 additions & 0 deletions .devcontainer/first-run-notice.txt
Expand Up @@ -6,3 +6,5 @@ Drivers Manual:
* KOTS will be on port http://localhost:30000 - check the skaffold logs
* `k` alias is available for `kubectl` with auto-completion for your pleasure
* This is a `zsh` terminal with Oh My Zsh installed. Just thought you should know.


1 change: 1 addition & 0 deletions .devcontainer/library-scripts/meta.env
@@ -0,0 +1 @@
VERSION='dev'
9 changes: 8 additions & 1 deletion .devcontainer/library-scripts/replicated-debian.sh
@@ -1,12 +1,19 @@
#!/usr/bin/env bash

# k3d
curl -s "https://raw.githubusercontent.com/rancher/k3d/main/install.sh" | bash
# v5 RC is needed to deterministically set the Registry port. Should be replaces with official release
curl -s https://raw.githubusercontent.com/rancher/k3d/main/install.sh | TAG=v5.0.0-rc.4 bash

# skaffold
curl -Lo /tmp/skaffold "https://storage.googleapis.com/skaffold/releases/latest/skaffold-linux-amd64"
sudo install /tmp/skaffold /usr/local/bin/

# Setup Skaffold
# TODO (dans): make this a bash variable
mkdir -p /home/codespace/.skaffold
cp /etc/replicated/skaffold.config /home/codespace/.skaffold/config
chown codespace:root /home/codespace/.skaffold/config

# kustomize
pushd /tmp
curl -s "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" | bash
Expand Down
46 changes: 46 additions & 0 deletions .devcontainer/library-scripts/replicated-userspace.sh
@@ -0,0 +1,46 @@
#!/usr/bin/env bash

# install Krew
# TODO (dans): ditch krew and just download the latest binaries on the path in Dockerfile
(
set -x; cd "$(mktemp -d)" &&
OS="$(uname | tr '[:upper:]' '[:lower:]')" &&
ARCH="$(uname -m | sed -e 's/x86_64/amd64/' -e 's/\(arm\)\(64\)\?.*/\1\2/' -e 's/aarch64$/arm64/')" &&
curl -fsSLO "https://github.com/kubernetes-sigs/krew/releases/latest/download/krew.tar.gz" &&
tar zxvf krew.tar.gz &&
KREW=./krew-"${OS}_${ARCH}" &&
"$KREW" install krew
)

# install krew plugins
kubectl krew install schemahero
kubectl krew install support-bundle
kubectl krew install preflights
kubectl krew install view-secret

# Make the cache from master branch
pushd /tmp
git clone https://github.com/replicatedhq/kots.git
pushd kots
# TODO (dans): find a way to cache images on image build
go mod download
popd
rm -rf kots
popd

# Clone any extra repos here

# Autocomplete Kubernetes
cat >> ~/.zshrc << EOF
source <(kubectl completion zsh)
alias k=kubectl
complete -F __start_kubectl k
EOF

# Set Git Editor Preference
cat >> ~/.zshrc << EOF
export VISUAL=vim
export EDITOR="$VISUAL"
EOF
39 changes: 1 addition & 38 deletions .devcontainer/lifecycle-scripts/onCreate.sh
@@ -1,52 +1,15 @@
#!/usr/bin/env bash

# Setup Skaffold
cp /etc/replicated/skaffold.config $HOME/.skaffold/config

# Setup the cluster
k3d cluster create --config /etc/replicated/k3d-cluster.yaml --kubeconfig-update-default

# install Krew
# TODO (dans): ditch krew and just download the latest binaries on the path in Dockerfile
(
set -x; cd "$(mktemp -d)" &&
OS="$(uname | tr '[:upper:]' '[:lower:]')" &&
ARCH="$(uname -m | sed -e 's/x86_64/amd64/' -e 's/\(arm\)\(64\)\?.*/\1\2/' -e 's/aarch64$/arm64/')" &&
curl -fsSLO "https://github.com/kubernetes-sigs/krew/releases/latest/download/krew.tar.gz" &&
tar zxvf krew.tar.gz &&
KREW=./krew-"${OS}_${ARCH}" &&
"$KREW" install krew
)

export PATH="${KREW_ROOT:-$HOME/.krew}/bin:$PATH"

# install krew plugins
kubectl krew install schemahero
kubectl krew install support-bundle
kubectl krew install preflights
kubectl krew install view-secret

# install schemahero in the cluster
kubectl schemahero install

k3d cluster stop replicated

# Make the cache
make cache
skaffold build

# Clone any extra repos here

# Autocomplete Kubernetes
cat >> ~/.zshrc << EOF
source <(kubectl completion zsh)
alias k=kubectl
complete -F __start_kubectl k
EOF

# Set Git Editor Preference
cat >> ~/.zshrc << EOF

export VISUAL=vim
export EDITOR="$VISUAL"
EOF
8 changes: 8 additions & 0 deletions skaffold.yaml
Expand Up @@ -9,6 +9,14 @@ profiles:
kustomize:
paths:
- "./kustomize/overlays/kotsstore"
- name: codespace
activation:
- env: USER=codespace
build:
local:
concurrency: 0
useBuildkit: true
push: true

build:
insecureRegistries:
Expand Down

0 comments on commit b1f6ba8

Please sign in to comment.