From 93507ce964e66c983ab561148dab0a4481e8b49e Mon Sep 17 00:00:00 2001 From: Radon Rosborough Date: Wed, 23 Dec 2020 18:00:52 -0800 Subject: [PATCH] Runtime image and further Makefile updates --- .dockerignore | 4 +-- Makefile | 42 ++++++++++++++++++---------- docker/runtime/Dockerfile | 9 ++++++ docker/runtime/install.bash | 39 ++++++++++++++++++++++++++ docker/runtime/pid1.bash | 10 +++++++ langs/python.yaml | 2 +- package.json | 1 + src/packager/make-script.js | 55 ++++++++++++++++++++++++++++++------- yarn.lock | 5 ++++ 9 files changed, 139 insertions(+), 28 deletions(-) create mode 100644 docker/runtime/Dockerfile create mode 100644 docker/runtime/install.bash create mode 100644 docker/runtime/pid1.bash diff --git a/.dockerignore b/.dockerignore index ce09fd5..860df0c 100644 --- a/.dockerignore +++ b/.dockerignore @@ -2,7 +2,5 @@ **/*.log **/.env **/.terraform -**/debs +**/build **/node_modules -**/pkg -**/work diff --git a/Makefile b/Makefile index 3b5dfcd..b66a750 100644 --- a/Makefile +++ b/Makefile @@ -3,9 +3,13 @@ SHELL := bash export PATH := bin:$(PATH) -include .env +-include .env export +BUILD := build/$(T)/$(L) +DEB := riju-$(T)-$(L).deb +S3_DEB := s3://$(S3_BUCKET_BASE)-debs/debs/$(T)/$(L)/$(DEB) + .PHONY: help help: @echo "usage:" @@ -29,16 +33,20 @@ runtime-image: app-image: docker build . -f docker/app/Dockerfile -t riju-app --pull +.PHONY: script +script: + @: $${L} $${T} + mkdir -p $(BUILD) + node src/packager/make-script --lang $(L) --type $(T) > $(BUILD)/build.bash + chmod +x $(BUILD)/build.bash + .PHONY: pkg pkg: - @: $${L} - mkdir -p build/$(L) - node src/packager/make-script $(L) > build/$(L)/build.bash - chmod +x build/$(L)/build.bash - rm -rf build/$(L)/src build/$(L)/pkg - mkdir -p build/$(L)/src build/$(L)/pkg - cd build/$(L)/src && pkg="$(PWD)/build/$(L)/pkg" ../build.bash - fakeroot dpkg-deb --build build/$(L)/pkg build/$(L)/$(L).deb + @: $${L} $${T} + rm -rf $(BUILD)/src $(BUILD)/pkg + mkdir -p $(BUILD)/src $(BUILD)/pkg + cd $(BUILD)/src && pkg="$(PWD)/$(BUILD)/pkg" ../build.bash + fakeroot dpkg-deb --build $(BUILD)/pkg $(BUILD)/$(DEB) ### Run things inside Docker @@ -54,46 +62,52 @@ runtime-shell: .PHONY: fetch-packaging-image fetch-packaging-image: + @: $${DOCKER_REPO_BASE} docker pull $(DOCKER_REPO_BASE)-packaging docker tag $(DOCKER_REPO_BASE)-packaging riju-packaging .PHONY: fetch-runtime-image fetch-runtime-image: + @: $${DOCKER_REPO_BASE} docker pull $(DOCKER_REPO_BASE)-runtime docker tag $(DOCKER_REPO_BASE)-runtime riju-runtime .PHONY: fetch-app-image fetch-app-image: + @: $${DOCKER_REPO_BASE} docker pull $(DOCKER_REPO_BASE)-app docker tag $(DOCKER_REPO_BASE)-app riju-app .PHONY: fetch-pkg fetch-pkg: - @: $${L} - mkdir -p build/$(L) - aws s3 cp s3://$(S3_BUCKET_BASE)-debs/debs/$(L).deb build/$(L)/$(L).deb + @: $${L} $${T} $${S3_BUCKET_BASE} + mkdir -p $(BUILD) + aws s3 cp $(S3_DEB) $(BUILD)/$(DEB) ### Publish things to registries .PHONY: publish-packaging-image publish-packaging-image: + @: $${DOCKER_REPO_BASE} docker tag riju-packaging $(DOCKER_REPO_BASE)-packaging docker push $(DOCKER_REPO_BASE)-packaging .PHONY: publish-runtime-image publish-runtime-image: + @: $${DOCKER_REPO_BASE} docker tag riju-runtime $(DOCKER_REPO_BASE)-runtime docker push $(DOCKER_REPO_BASE)-runtime .PHONY: publish-app-image publish-app-image: + @: $${DOCKER_REPO_BASE} docker tag riju-app $(DOCKER_REPO_BASE)-app docker push $(DOCKER_REPO_BASE)-app .PHONY: publish-pkg publish-pkg: - @: $${L} - aws s3 cp build/$(L)/$(L).deb s3://$(S3_BUCKET_BASE)-debs/debs/$(L).deb + @: $${L} $${T} $${S3_BUCKET_BASE} + aws s3 cp $(BUILD)/$(DEB) $(S3_DEB) ### Miscellaneous diff --git a/docker/runtime/Dockerfile b/docker/runtime/Dockerfile new file mode 100644 index 0000000..b1c9de6 --- /dev/null +++ b/docker/runtime/Dockerfile @@ -0,0 +1,9 @@ +FROM ubuntu:rolling + +COPY docker/runtime/install.bash /tmp/ +RUN /tmp/install.bash + +WORKDIR /src +COPY docker/runtime/pid1.bash /usr/local/sbin/ +ENTRYPOINT ["/usr/local/sbin/pid1.bash"] +CMD ["bash"] diff --git a/docker/runtime/install.bash b/docker/runtime/install.bash new file mode 100644 index 0000000..8aeca25 --- /dev/null +++ b/docker/runtime/install.bash @@ -0,0 +1,39 @@ +#!/usr/bin/env bash + +set -euxo pipefail + +export DEBIAN_FRONTEND=noninteractive + +apt-get update +(yes || true) | unminimize + +apt-get install -y curl gnupg lsb-release + +curl -sSL https://deb.nodesource.com/gpgkey/nodesource.gpg.key | apt-key add - +curl -sSL https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - + +ubuntu_ver="$(lsb_release -rs)" +ubuntu_name="$(lsb_release -cs)" + +node_repo="$(curl -sS https://deb.nodesource.com/setup_current.x | grep NODEREPO= | grep -Eo 'node_[0-9]+\.x' | head -n1)" + +tee -a /etc/apt/sources.list.d/custom.list >/dev/null </dev/null <<"EOF" +%sudo ALL=(ALL:ALL) NOPASSWD: ALL +EOF + +rm "$0" diff --git a/docker/runtime/pid1.bash b/docker/runtime/pid1.bash new file mode 100644 index 0000000..0689f59 --- /dev/null +++ b/docker/runtime/pid1.bash @@ -0,0 +1,10 @@ +#!/usr/bin/env bash + +set -euo pipefail + +groupadd -g "$(stat -c %g "$PWD")" -o -p '!' -r riju +useradd -u "$(stat -c %u "$PWD")" -g "$(stat -c %g "$PWD")" -o -m -N -l -s /usr/bin/bash -G sudo riju + +runuser -u riju touch /home/riju/.sudo_as_admin_successful + +exec runuser -u riju "$@" diff --git a/langs/python.yaml b/langs/python.yaml index 0be4bc9..c6517d1 100644 --- a/langs/python.yaml +++ b/langs/python.yaml @@ -18,7 +18,7 @@ install: wget "$(curl -sSL "https://pvsc.blob.core.windows.net/python-language-server-stable?restype=container&comp=list&prefix=Python-Language-Server-linux-x64" | grep -Eo 'https://[^<]+\.nupkg' | tail -n1)" unzip -d "${pkg}/opt/mspyls" Python-Language-Server-linux-x64.*.nupkg chmod +x "${pkg}/opt/mspyls/Microsoft.Python.LanguageServer" - ln -s "${pkg}/opt/mspyls/Microsoft.Python.LanguageServer" "${pkg}/usr/local/bin/Microsoft.Python.LanguageServer" + ln -s "/opt/mspyls/Microsoft.Python.LanguageServer" "${pkg}/usr/local/bin/Microsoft.Python.LanguageServer" repl: >- python3 -u diff --git a/package.json b/package.json index f83d9a0..427394b 100644 --- a/package.json +++ b/package.json @@ -5,6 +5,7 @@ "private": true, "type": "module", "dependencies": { + "commander": "^6.2.1", "yaml": "^1.10.0" } } diff --git a/src/packager/make-script.js b/src/packager/make-script.js index 38dc328..bb6f45d 100644 --- a/src/packager/make-script.js +++ b/src/packager/make-script.js @@ -1,11 +1,15 @@ import process from "process"; +import { Command } from "commander"; + import { readLangConfig } from "../config.js"; // Given a language config object, return the text of a Bash script -// that will build the (unpacked) Debian package into ${pkg} when run in an -// appropriate environment. -function makeScript(langConfig) { +// that will build the (unpacked) riju-lang-foo Debian package into +// ${pkg} when run in an appropriate environment. This is a package +// that will install the language interpreter/compiler and associated +// tools. +function makeLangScript(langConfig) { const { id, name, @@ -19,7 +23,7 @@ function makeScript(langConfig) { set -euxo pipefail`); let debianControlData = `\ Package: riju-lang-${id} -Version: ${timestamp} +Version: \$(date +%s%3N) Architecture: amd64 Maintainer: Radon Rosborough Description: The ${name} language packaged for Riju`; @@ -29,7 +33,7 @@ Depends: ${apt.join(", ")}`; } parts.push(`\ install -d "\${pkg}/DEBIAN" -cat <<"EOF" > "\${pkg}/DEBIAN/control" +cat < "\${pkg}/DEBIAN/control" ${debianControlData} EOF`); for (const part of manual || []) { @@ -38,14 +42,45 @@ EOF`); return parts.join("\n\n"); } +// Given a language config object, return the text of a Bash script +// that will build the (unpacked) riju-config-foo Debian package into +// ${pkg} when run in an appropriate environment. This is a package +// that will install configuration files and/or small scripts that +// encode the language configuration so that Riju can operate on any +// installed languages without knowing their configuration in advance. +function makeConfigScript(langConfig) { + // +} + +// Given a language config object, return the text of a Bash script +// that will build the (unpacked) riju-shared-foo Debian package into +// ${pkg} when run in an appropriate environment. This is a package +// that installs tools used by multiple languages, and can be declared +// as a dependency. +function makeSharedScript(langConfig) { + throw new Error("shared script generation not implemented yet"); +} + +// Parse command-line arguments, run main functionality, and exit. async function main() { - const args = process.argv.slice(2); - if (args.length !== 1) { - console.error("usage: script-maker.js LANG"); + const program = new Command(); + program + .requiredOption("--lang ", "language ID") + .requiredOption( + "--type ", + "package category (lang, config, shared)" + ); + program.parse(process.argv); + const scriptMaker = { + lang: makeLangScript, + config: makeConfigScript, + shared: makeSharedScript, + }[program.type]; + if (!scriptMaker) { + console.error(`make-script.js: unsupported --type ${program.type}`); process.exit(1); } - const [lang] = args; - console.log(makeScript(await readLangConfig(lang))); + console.log(scriptMaker(await readLangConfig(program.lang))); process.exit(0); } diff --git a/yarn.lock b/yarn.lock index a24537e..78bd03a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2,6 +2,11 @@ # yarn lockfile v1 +commander@^6.2.1: + version "6.2.1" + resolved "https://registry.yarnpkg.com/commander/-/commander-6.2.1.tgz#0792eb682dfbc325999bb2b84fddddba110ac73c" + integrity sha512-U7VdrJFnJgo4xjrHpTzu0yrHPGImdsmD95ZlgYSEajAn2JKzDhDTPG9kBTefmObL2w/ngeZnilk+OV9CG3d7UA== + yaml@^1.10.0: version "1.10.0" resolved "https://registry.yarnpkg.com/yaml/-/yaml-1.10.0.tgz#3b593add944876077d4d683fee01081bd9fff31e"