Skip to content

Commit

Permalink
[images/*] Don't modify .bashrc and use ENV PATH instead for modify…
Browse files Browse the repository at this point in the history
…ing paths
  • Loading branch information
auguwu committed Nov 3, 2022
1 parent 13d628a commit 4d661f2
Show file tree
Hide file tree
Showing 8 changed files with 258 additions and 41 deletions.
15 changes: 6 additions & 9 deletions images/base/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ RUN groupadd -g ${USER_GID} ${USERNAME} && \
RUN git lfs install --system

# stuff here
ENV GITHUB_CLI_VERSION="2.18.1"
ENV GITHUB_CLI_VERSION="2.19.0"
ENV CODER_CLI_VERSION="0.11.0"
ENV TERRAFORM_VERSION="1.3.3"
ENV KUBECTL_VERSION="1.25.3"
Expand Down Expand Up @@ -75,7 +75,9 @@ RUN set -eux; \
curl -L -s ${CODER_DOWNLOAD_URL} | tar xfz - -C /opt/coder/cli --strip-components=1; \
curl -L -s ${GITHUB_CLI_DOWNLOAD_URL} | tar xfz - -C /opt/github/cli --strip-components=1; \
curl -L -s ${HELM_DOWNLOAD_URL} | tar xfz - -C /opt/helm --strip-components=1; \
curl -L -s ${TERRAFORM_DOWNLOAD_URL} | bsdtar xvf - --strip-components=1 -C /opt/hashicorp/terraform;
curl -L -o /tmp/terraform.zip ${TERRAFORM_DOWNLOAD_URL}; \
unzip -qd /opt/hashicorp/terraform /tmp/terraform.zip; \
rm /tmp/*.zip;

# Let the user execute `kubectl`
RUN chmod +x /usr/local/bin/kubectl
Expand All @@ -84,12 +86,7 @@ RUN chmod +x /usr/local/bin/kubectl
USER ${USERNAME}
WORKDIR /home/${USERNAME}

# Set paths to coder, gh, and terraform
RUN echo "export PATH=\"\$PATH:/opt/coder/cli\"" >> /home/${USERNAME}/.bashrc
RUN echo "export PATH=\"\$PATH:/opt/hashicorp/terraform\"" >> /home/${USERNAME}/.bashrc
RUN echo "export PATH=\"\$PATH:/opt/github/cli/bin\"" >> /home/${USERNAME}/.bashrc
RUN echo "export PATH=\"\$PATH:/opt/helm\"" >> /home/${USERNAME}/.bashrc
RUN echo "export PATH=\"\$PATH:/home/${USERNAME}/.local/bin\"" >> /home/${USERNAME}/.bashrc
ENV PATH=$PATH:/opt/coder/cli:/opt/hashicorp/terraform:/opt/helm:/opt/github/cli/bin:/home/${USERNAME}/.local/bin

# Add common Helm repositores
RUN /opt/helm/helm repo add bitnami https://charts.bitnami.com/bitnami
RUN helm repo add bitnami https://charts.bitnami.com/bitnami
4 changes: 2 additions & 2 deletions images/base/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ This image is the main base for all of the images in this repository. It uses th
## Bundled Software
| Name | Description | Version |
| ----------- | --------------------------------------------------------------------------------- | --------------------- |
| GitHub CLI | GitHub's official command line utility | [v2.18.1][github-cli] |
| GitHub CLI | GitHub's official command line utility | [v2.19.0][github-cli] |
| Coder (OSS) | Remote development environments on your infrastructure provisioned with Terraform | [v0.11.0][coder] |
| Terraform | Automate Infrastructure on Any Cloud | [v1.3.3][terraform] |
| `kubectl` | kubectl controls the Kubernetes cluster manager. | [v1.25.3][kubectl] |
| `helm` | The Kubernetes Package Manager | [v3.10.1][helm] |

[github-cli]: https://github.com/cli/cli/releases/tag/v2.18.1
[github-cli]: https://github.com/cli/cli/releases/tag/v2.19.0
[terraform]: https://github.com/hashicorp/terraform/releases/tag/v1.3.3
[kubectl]: https://github.com/kubernetes/kubernetes/releases/tag/v1.25.3
[coder]: https://github.com/coder/coder/releases/tag/v0.11.0
Expand Down
26 changes: 5 additions & 21 deletions images/golang/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -48,27 +48,11 @@ RUN set -eux; \
GOLANGCI_DOWNLOAD_URL="https://github.com/golangci/golangci-lint/releases/download/v${GOLANGCI_VERSION}/golangci-lint-${GOLANGCI_VERSION}-linux-amd64.tar.gz" \
;; \
esac; \
mkdir -p /opt/golang; \
mkdir -p /opt/tools/goreleaser; \
mkdir -p /opt/tools/_golangci; \
curl -L -o /tmp/golang.tar.gz ${GO_DOWNLOAD_URL}; \
tar -xf /tmp/golang.tar.gz -C /opt/golang; \
curl -L -o /tmp/goreleaser.tar.gz ${GORELEASER_DOWNLOAD_URL}; \
tar -xf /tmp/goreleaser.tar.gz -C /opt/tools/goreleaser; \
curl -L -o /tmp/golangci.tar.gz ${GOLANGCI_DOWNLOAD_URL}; \
tar -xf /tmp/golangci.tar.gz -C /opt/tools/_golangci; \
rm /tmp/*.tar.gz;

# Fix up the directory structure for GolangCI tools.
RUN set -eux; \
mkdir -p /opt/tools/golangci; \
cp /opt/tools/_golangci/**/LICENSE /opt/tools/golangci/LICENSE; \
cp /opt/tools/_golangci/**/README.md /opt/tools/golangci/README.md; \
cp /opt/tools/_golangci/**/golangci-lint /opt/tools/golangci/golangci-lint; \
rm -rf /opt/tools/_golangci;
mkdir -p /opt/golang/go /opt/golang/tools/golangci /opt/golang/tools/goreleaser; \
curl -L -s ${GO_DOWNLOAD_URL} | tar xfz - -C /opt/golang/go --strip-components=1 --no-same-owner; \
curl -L -s ${GORELEASER_DOWNLOAD_URL} | tar xfz - -C /opt/golang/tools/goreleaser --no-same-owner; \
curl -L -s ${GOLANGCI_DOWNLOAD_URL} | tar xfz - -C /opt/golang/tools/golangci --strip-components 1 --no-same-owner;

USER ${USERNAME}

RUN echo "export PATH=\"\$PATH:/opt/golang/go/bin\"" >> /home/${USERNAME}/.bashrc
RUN echo "export PATH=\"\$PATH:/opt/tools/goreleaser\"" >> /home/${USERNAME}/.bashrc
RUN echo "export PATH=\"\$PATH:/opt/tools/golangci\"" >> /home/${USERNAME}/.bashrc
ENV PATH=$PATH:/opt/golang/go/bin:/opt/golang/tools/goreleaser:/opt/golang/tools/golangci
13 changes: 8 additions & 5 deletions images/java/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ ENV JDK_VERSION="18.0.2.1"
ENV GRADLE_VERSION="7.5.1"
ENV MAVEN_VERSION="3.8.6"

# boop
RUN DEBIAN_FRONTEND="noninteractive" apt install -y libarchive-tools

# Install packages!
RUN set -eux; \
arch="$(dpkg --print-architecture)"; \
Expand All @@ -51,12 +54,12 @@ RUN set -eux; \
mkdir -p /opt/maven; \
curl -L -s ${TEMURIN_DOWNLOAD_URL} | tar xfz - -C /opt/java/jdk --strip-components=1; \
curl -L -s ${MAVEN_DOWNLOAD_URL} | tar xfz - -C /opt/maven --strip-components=1; \
curl -L -s ${GRADLE_DOWNLOAD_URL} | bsdtar xvf - --strip-components=1 -C /opt/gradle;
curl -L -s ${GRADLE_DOWNLOAD_URL} | bsdtar xfz - --strip-components=1 -C /opt/gradle;

RUN chmod +x /opt/gradle/bin/gradle

# Go back as the user
USER ${USERNAME}

RUN echo "export PATH=\"\$PATH:/opt/java/jdk/bin\"" >> /home/${USERNAME}/.bashrc
RUN echo "export PATH=\"\$PATH:/opt/maven/bin\"" >> /home/${USERNAME}/.bashrc
RUN echo "export PATH=\"\$PATH:/opt/gradle/bin\"" >> /home/${USERNAME}/.bashrc
RUN echo "export JAVA_HOME=\"/opt/java/jdk\"" >> /home/${USERNAME}/.bashrc
ENV JAVA_HOME=/opt/java/jdk
ENV PATH=$PATH:$JAVA_HOME/bin:/opt/maven/bin:/opt/gradle/bin
2 changes: 1 addition & 1 deletion images/node/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,4 @@ RUN set -eux;

USER ${USERNAME}

RUN echo "export PATH=\"\$PATH:/opt/nodejs/bin\"" >> /home/${USERNAME}/.bashrc
ENV PATH=$PATH:/opt/nodejs/bin
3 changes: 0 additions & 3 deletions templates/charted-server/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,6 @@ resource "coder_agent" "main" {
cp /etc/skel/.bashrc $HOME
fi
echo "export PATH=\"$PATH:/opt/coder/cli:/opt/hashicorp/terraform:/opt/github/cli/bin:/opt/helm:/home/noel/.local/bin:/opt/java/jdk/bin:/opt/maven/bin:/opt/gradle/bin\"" >> /home/noel/.bashrc
echo "export JAVA_HOME=\"/opt/java/jdk\"" >> /home/noel/.bashrc
# This script installs JetBrains Projector, I'm fine with the latency, but
# you might not.
PROJECTOR_LOGS=/home/noel/.logs/projector.log
Expand Down
45 changes: 45 additions & 0 deletions templates/code-server/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

191 changes: 191 additions & 0 deletions templates/code-server/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
# 💐💚 coder-images: Optimized, and easy Docker images and Coder templates to use in your everyday work!
# Copyright (c) 2022 Noel <[email protected]>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

terraform {
required_providers {
coder = {
source = "coder/coder"
version = "0.6.0"
}

kubernetes = {
source = "hashicorp/kubernetes"
version = "2.14.0"
}
}
}

provider "kubernetes" {
config_path = var.use_host_kubeconfig == true ? "~/.kube/config" : null
}

variable "workspace_name" {
description = "Workspace name to use for Kubernetes pod & volume"
type = string
}

variable "dotfiles_repo" {
description = "The repository URL to your dotfiles configuration"
default = ""
type = string
}

variable "use_host_kubeconfig" {
description = "This variable allows you to use the host pod's Kubernetes configuration"
sensitive = true
default = false
type = bool
}

variable "namespace" {
description = "Kubernetes namespace to use for the pod."
default = "noel-system"
type = string
}

variable "docker_image_type" {
description = "The Docker image flavour to use"
default = "node"
type = string

validation {
condition = contains(["node", "golang", "rust"], var.docker_image_type)
error_message = "Docker image flavour is not a valid one~!"
}
}

variable "git_repository" {
description = "The Git repository to initialize, if any."
default = ""
type = string
}

data "coder_workspace" "me" {
}

resource "coder_agent" "main" {
arch = "arm64"
dir = "/home/noel"
os = "linux"

startup_script = <<-EOL
#!/bin/bash
if [ ! -f ~/.profile ]; then
cp /etc/skel/.profile $HOME
fi
if [ ! -f ~/.bashrc ]; then
cp /etc/skel/.bashrc $HOME
fi
# install and start code-server
curl -fsSL https://code-server.dev/install.sh | sh
code-server --auth none --port 3621
${var.git_repository != "" ? "sudo git clone ${var.git_repository} /workspace" : ""}
EOL
}

resource "coder_app" "code-server" {
agent_id = coder_agent.main.id
slug = "code-server"
display_name = "VSCode"
url = "http://localhost:3621/?folder=${var.git_repository != "" ? "/workspace" : "/home/noel"}"
icon = "/icon/code.svg"

healthcheck {
url = "http://localhost:3621/healthz"
interval = 2
threshold = 10
}
}

resource "kubernetes_persistent_volume_claim" "awa" {
metadata {
namespace = var.namespace
name = var.workspace_name
}

wait_until_bound = false
spec {
access_modes = ["ReadWriteOnce"]
resources {
requests = {
storage = "10Gi"
}
}
}
}

resource "kubernetes_pod" "workspace" {
metadata {
name = var.workspace_name
namespace = var.namespace

labels = {
"k8s.noelware.cloud/component" = "coder",
"k8s.noelware.cloud/template" = "code-server"
}
}

spec {
security_context {
run_as_user = "1000"
fs_group = "1000"
}

container {
name = "workspace"
image = "ghcr.io/auguwu/coder-images/${var.docker_image_type}:latest"
command = ["/bin/bash", "-c", coder_agent.main.init_script]
image_pull_policy = "Always"

env {
name = "CODER_ACCESS_URL"
value = "https://coder.floofy.dev"
}

env {
name = "CODER_AGENT_TOKEN"
value = coder_agent.main.token
}

volume_mount {
mount_path = "/home/noel"
read_only = false
name = "workspace"
}

security_context {
run_as_user = "1000"
}
}

volume {
name = "workspace"
persistent_volume_claim {
claim_name = var.workspace_name
read_only = false
}
}
}
}

0 comments on commit 4d661f2

Please sign in to comment.