From 1d79a803f7c49b15d062c2564bd1a123e87cf75c Mon Sep 17 00:00:00 2001 From: OCram85 Date: Mon, 7 Nov 2022 16:01:31 +0100 Subject: [PATCH] Adds basic container setup with pipeline (#1) #### :book: Summary - adds dockerfile - adds woodpecker pipelines #### :bookmark_tabs: Test Plan > :bulb: Select your test plan for the code changes. - [x] Tested with CI pipeline - [ ] Custom test - [ ] No test plan ##### Details / Justification #### :books: Additional Notes Co-authored-by: OCram85 Reviewed-on: https://gitea.ocram85.com/CodeServer/Container/pulls/1 --- .woodpecker/.master.yml | 21 +++++++ .woodpecker/.next.yml | 19 ++++++ .woodpecker/.test.yml | 9 +++ Dockerfile | 27 +++----- install-devruntime | 133 ++++++++++++++++++++++++++++++++++++++++ 5 files changed, 191 insertions(+), 18 deletions(-) create mode 100644 .woodpecker/.master.yml create mode 100644 .woodpecker/.next.yml create mode 100644 .woodpecker/.test.yml create mode 100755 install-devruntime diff --git a/.woodpecker/.master.yml b/.woodpecker/.master.yml new file mode 100644 index 0000000..dee547b --- /dev/null +++ b/.woodpecker/.master.yml @@ -0,0 +1,21 @@ +depends_on: + - test + +pipeline: + buildMasterGitea: + image: plugins/docker + settings: + registry: gitea.ocram85.com + repo: gitea.ocram85.com/codeserver/container + dockerfile: Dockerfile + auto_tag: true + #build_args: + # - NODE_BASE=lts-buster-slim + # - NGINX_BASE=1.23.1-alpine + username: + from_secret: gitea_user + password: + from_secret: gitea_passwd + when: + event: push + branch: master diff --git a/.woodpecker/.next.yml b/.woodpecker/.next.yml new file mode 100644 index 0000000..748dc9b --- /dev/null +++ b/.woodpecker/.next.yml @@ -0,0 +1,19 @@ +depends_on: + - test + +pipeline: + buildNextGitea: + image: woodpeckerci/plugin-docker-buildx + settings: + #dry_run: true + registry: gitea.ocram85.com + repo: gitea.ocram85.com/codeserver/container + platforms: linux/amd64 + dockerfile: Dockerfile + tags: next + username: + from_secret: gitea_user + password: + from_secret: gitea_passwd + when: + event: pull_request diff --git a/.woodpecker/.test.yml b/.woodpecker/.test.yml new file mode 100644 index 0000000..0662512 --- /dev/null +++ b/.woodpecker/.test.yml @@ -0,0 +1,9 @@ +pipeline: + testDockerfile: + image: plugins/docker + settings: + dry_run: true + registry: gitea.ocram85.com + repo: gitea.ocram85.com/codeserver/container + dockerfile: Dockerfile + tags: next diff --git a/Dockerfile b/Dockerfile index dcf7537..ee60171 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,28 +2,19 @@ FROM linuxserver/code-server:4.7.1 RUN \ echo "**** install starshipt prompt ****" && \ - curl -sS https://starship.rs/install.sh | sh && \ + curl -sS https://starship.rs/install.sh | sh -s -- -f && \ echo "eval \"\$(starship init bash)\"" >> /etc/bash.bashrc -ENV STARSHIP_CONFIG=/etc/starship.tom +ENV STARSHIP_CONFIG=/etc/starship.toml -COPY staship.toml /etc/starship.toml +COPY starship.toml /etc/starship.toml RUN \ - "**** setup git ****" && \ - git config --system credential.helper store + echo "**** setup git ****" && \ + git config --system credential.helper store && \ + echo 'source /usr/share/bash-completion/completions/git' >> /etc/bash.bashrc +ADD install-devruntime /usr/bin/ RUN \ - echo "**** install dev runtimes ****" && \ - curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash - && \ - apt-get update && \ - apt-get install -y \ - nodejs \ - golang-go &&\ - echo "**** clean up ****" && \ - apt-get clean && \ - rm -rf \ - /config/* \ - /tmp/* \ - /var/lib/apt/lists/* \ - /var/tmp/* + chmod +x /usr/bin/install-devruntime && \ + echo "echo \"Use 'install-devruntime' to install missing runtimes like dotnet or NodeJs.\"" >> /etc/bash.bashrc diff --git a/install-devruntime b/install-devruntime new file mode 100755 index 0000000..58b2a9d --- /dev/null +++ b/install-devruntime @@ -0,0 +1,133 @@ +#!/bin/bash + +set -e + +function showHelp() { + cat <&2 + else + echo -e "\e[31mInstall-DevRuntime\e[0m: $1" 1>&2 + fi +} + +function instDotNet() { + say "Downloading latest install script..." "dotnet" + curl -fsSL https://dot.net/v1/dotnet-install.sh -o /tmp/dotnet-install.sh + chmod +x /tmp/dotnet-install.sh + + say "Installing latest .NET Core LTS release..." "dotnet" + /tmp/dotnet-install.sh --channel LTS + echo 'export PATH=$PATH:/config/.dotnet' | sudo tee -a /etc/bash.bashrc > /dev/null + + say "dotnet done. " "dotnet" +} + +function instGoLang() { + if [[ -z "$1" ]]; then + GOVERSION="1.19.3" + else + GOVERSION="$1" + fi + + say "Downloading golang ($GOVERSION)..." "GoLang" + curl -fsSL "https://go.dev/dl/go$GOVERSION.linux-amd64.tar.gz" -o /tmp/golang.tar.gz + say "Installing golang ($GOVERSION)...." "GoLang" + sudo rm -rf /usr/local/go + sudo tar -C /usr/local -xzf /tmp/golang.tar.gz + echo 'export PATH=$PATH:/usr/local/go/bin' | sudo tee -a /etc/bash.bashrc > /dev/null + say "Cleaning up..." "GoLang" + rm -f /tmp/golang.tar.gz + say "done." "GoLang" + say "Please reload bash profile to finalize." "GoLang" +} + +function instNodeJs() { + say "Adding nodesource package source (NodeJS LTS)..." "NodeJs" + curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash - + say "Updating package lists and installing NodeJS LTS..." "NodeJs" + sudo apt-get install --no-install-recommends -y \ + nodejs + + say "Cleaning up..." "NodeJs" + sudo apt-get clean + sudo rm -rf \ + /tmp/* \ + /var/lib/apt/lists/* \ + /var/tmp/* + + say "done." "NodeJs" +} + +function instPwsh() { + say "Installing PowerShell requirements..." "PowerShell" + sudo apt-get install --no-install-recommends -y \ + apt-transport-https \ + software-properties-common + + say "Adding powershell package sources..." "PowerShell" + # Download the Microsoft repository GPG keys + curl -fsSL "https://packages.microsoft.com/config/ubuntu/$(lsb_release -rs)/packages-microsoft-prod.deb" -o /tmp/packages-microsoft-prod.deb + # Register the Microsoft repository GPG keys + sudo dpkg -i /tmp/packages-microsoft-prod.deb + # Update the list of packages after we added packages.microsoft.com + sudo apt-get update + + say "Installing PowerShell..." "PowerShell" + # Install PowerShell + sudo apt-get install --no-install-recommends -y powershell + + echo "done." "PowerShell" +} + +function main() { + if [[ "$#" == "0" ]]; then + showHelp + exit 0 + fi + + for i in $@; do + if [[ "$1" == "-h" ]]; then + showHelp + exit 0 + elif [[ "$i" == "dotnet" ]]; then + instDotNet + elif [[ "$i" == "golang" ]]; then + instGoLang + elif [[ "$i" == "nodejs" ]]; then + instNodeJs + elif [[ "$i" == "powershell" ]]; then + instPwsh + else + sayE "Unknown parameter value given!($i)." + showHelp + exit 1 + fi + done +} + +main $@