UNPKG

@adp-psych/container-tools

Version:

Tools for using containers for psychology experiments

134 lines (124 loc) 3.6 kB
/* * Copyright (C) 2021, 2022 Anthony Di Pietro * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. */ /** * @file Installs [cert-manager](https://cert-manager.io/) * to a [Kubernetes](https://kubernetes.io/) cluster * using [Helm](https://helm.sh/). * * @module module:install-cert-manager * @requires console-exec * @author Anthony Di Pietro <anthony.dipietro@research.uwa.edu.au> * @copyright © 2021, 2022 Anthony Di Pietro * @license AGPL-3.0-or-later */ const {consoleSpawn} = require('./console-exec.js'); const { addRepository, updateRepositories, upgradeInstall, } = require('./helm.js'); /** * The name of the repository containing the Helm chart. * * @constant {String} * @static * @access protected */ const REPOSITORY_NAME = 'jetstack'; /** * The URL of the repository containing the Helm chart. * * @constant {String} * @static * @access protected */ const REPOSITORY_URL = 'https://charts.jetstack.io/'; /** * The name of the * [Kubernetes secret](https://kubernetes.io/docs/concepts/configuration/secret/) * for the * [DigitalOcean API token](https://docs.digitalocean.com/reference/api/create-personal-access-token/). * * @constant {String} * @static * @access protected */ const SECRET_NAME = 'digitalocean-dns'; /** * Creates a * [Kubernetes secret](https://kubernetes.io/docs/concepts/configuration/secret/) * for the * [DigitalOcean API token](https://docs.digitalocean.com/reference/api/create-personal-access-token/). * * @static * @access protected * @param {String} apiToken - The DigitalOcean API token. * @example * createSecret(); // Creates the secret. */ const createSecret = async (apiToken) => { try { await consoleSpawn('kubectl', [ 'delete', 'secret', SECRET_NAME, ]); } catch { /* Ignore failure to delete secret, as it may not exist. */ } await consoleSpawn('kubectl', [ 'create', 'secret', 'generic', SECRET_NAME, `--from-literal=api-token=${apiToken}`, ]); }; /** * Installs/upgrades cert-manager using Helm. * * @static * @access protected * @param {String} version - The version of cert-manager to install. * @example * // Installs/upgrades cert-manager to version 1.9.1. * helmUpgradeCertManager('1.9.1'); */ const helmUpgradeCertManager = async (version) => { await upgradeInstall('cert-manager', 'jetstack/cert-manager', [ `--version=${version}`, '--set', 'installCRDs=true', ]); }; /** * Installs/upgrades cert-manager using Helm. * * @static * @param {String} version - The version of cert-manager to install. * @param {String} apiToken - The DigitalOcean API token. * @example * // Installs/upgrades cert-manager to version 1.9.1. * installCertManager('1.9.1', 'abc'); */ const installCertManager = async (version, apiToken) => { await createSecret(apiToken); await addRepository(REPOSITORY_NAME, REPOSITORY_URL); await updateRepositories(); await helmUpgradeCertManager(version); }; module.exports = installCertManager;