2019-03-04 05:51:52 +07:00
|
|
|
#!/usr/bin/env node
|
|
|
|
|
|
|
|
var { exec } = require('./utils/exec');
|
|
|
|
var fs = require('fs');
|
|
|
|
|
2019-03-24 22:37:31 +07:00
|
|
|
async function buildDockerImages() {
|
|
|
|
console.log("[BOOTSTRAP] Building required Docker images...");
|
|
|
|
|
2019-03-04 05:51:52 +07:00
|
|
|
console.log('Build authelia-example-backend docker image.')
|
|
|
|
await exec('docker build -t authelia-example-backend example/compose/nginx/backend');
|
|
|
|
|
2019-03-24 21:15:49 +07:00
|
|
|
console.log('Build authelia-duo-api docker image.')
|
|
|
|
await exec('docker build -t authelia-duo-api example/compose/duo-api');
|
2019-03-24 22:37:31 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
async function checkHostsFile() {
|
|
|
|
async function checkAndFixEntry(entries, domain, ip) {
|
|
|
|
const foundEntry = entries.filter(l => l[1] == domain);
|
|
|
|
if (foundEntry.length > 0) {
|
|
|
|
if (foundEntry[0][0] == ip) {
|
|
|
|
// The entry exists and is correct.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// We need to remove the entry and replace it.
|
|
|
|
console.log(`Update entry for ${domain}.`);
|
|
|
|
await exec(`cat /etc/hosts | grep -v "${domain}" | /usr/bin/sudo tee /etc/hosts > /dev/null`);
|
|
|
|
await exec(`echo "${ip} ${domain}" | /usr/bin/sudo tee -a /etc/hosts > /dev/null`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// We need to add the new entry.
|
|
|
|
console.log(`Add entry for ${domain}.`);
|
|
|
|
await exec(`echo "${ip} ${domain}" | /usr/bin/sudo tee -a /etc/hosts > /dev/null`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
console.log("[BOOTSTRAP] Checking if example.com domain is forwarded to your machine...");
|
|
|
|
const actualEntries = fs.readFileSync("/etc/hosts").toString("utf-8")
|
|
|
|
.split("\n").filter(l => l !== '').map(l => l.split(" ").filter(w => w !== ''));
|
|
|
|
|
2019-03-28 05:09:01 +07:00
|
|
|
await checkAndFixEntry(actualEntries, 'login.example.com', '192.168.240.100');
|
|
|
|
await checkAndFixEntry(actualEntries, 'admin.example.com', '192.168.240.100');
|
|
|
|
await checkAndFixEntry(actualEntries, 'singlefactor.example.com', '192.168.240.100');
|
|
|
|
await checkAndFixEntry(actualEntries, 'dev.example.com', '192.168.240.100');
|
|
|
|
await checkAndFixEntry(actualEntries, 'home.example.com', '192.168.240.100');
|
|
|
|
await checkAndFixEntry(actualEntries, 'mx1.mail.example.com', '192.168.240.100');
|
|
|
|
await checkAndFixEntry(actualEntries, 'mx2.mail.example.com', '192.168.240.100');
|
|
|
|
await checkAndFixEntry(actualEntries, 'public.example.com', '192.168.240.100');
|
|
|
|
await checkAndFixEntry(actualEntries, 'secure.example.com', '192.168.240.100');
|
|
|
|
await checkAndFixEntry(actualEntries, 'mail.example.com', '192.168.240.100');
|
2019-03-24 22:37:31 +07:00
|
|
|
await checkAndFixEntry(actualEntries, 'duo.example.com', '192.168.240.100');
|
2019-03-28 05:09:01 +07:00
|
|
|
|
2019-04-11 02:27:18 +07:00
|
|
|
// For Traefik suite.
|
|
|
|
await checkAndFixEntry(actualEntries, 'traefik.example.com', '192.168.240.100');
|
|
|
|
|
2019-03-28 05:09:01 +07:00
|
|
|
// For testing network ACLs.
|
|
|
|
await checkAndFixEntry(actualEntries, 'proxy-client1.example.com', '192.168.240.201');
|
|
|
|
await checkAndFixEntry(actualEntries, 'proxy-client2.example.com', '192.168.240.202');
|
|
|
|
await checkAndFixEntry(actualEntries, 'proxy-client3.example.com', '192.168.240.203');
|
2019-03-24 22:37:31 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
async function checkKubernetesDependencies() {
|
|
|
|
console.log("[BOOTSTRAP] Checking Kubernetes tools in /tmp to allow testing a Kube cluster... (no junk installed on host)");
|
2019-03-24 21:15:49 +07:00
|
|
|
|
2019-03-04 05:51:52 +07:00
|
|
|
if (!fs.existsSync('/tmp/kind')) {
|
|
|
|
console.log('Install Kind for spawning a Kubernetes cluster.');
|
2019-04-25 04:52:08 +07:00
|
|
|
await exec('wget -nv https://github.com/kubernetes-sigs/kind/releases/download/v0.5.1/kind-linux-amd64 -O /tmp/kind && chmod +x /tmp/kind');
|
2019-03-04 05:51:52 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!fs.existsSync('/tmp/kubectl')) {
|
|
|
|
console.log('Install Kubectl for interacting with Kubernetes.');
|
2019-04-25 04:52:08 +07:00
|
|
|
await exec('wget -nv https://storage.googleapis.com/kubernetes-release/release/v1.13.0/bin/linux/amd64/kubectl -O /tmp/kubectl && chmod +x /tmp/kubectl');
|
2019-03-04 05:51:52 +07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-24 22:37:31 +07:00
|
|
|
async function main() {
|
|
|
|
await checkHostsFile();
|
|
|
|
await buildDockerImages();
|
|
|
|
await checkKubernetesDependencies();
|
|
|
|
}
|
|
|
|
|
2019-03-04 05:51:52 +07:00
|
|
|
main().catch((err) => {
|
|
|
|
console.error(err);
|
|
|
|
process.exit(1);
|
2019-04-25 04:52:08 +07:00
|
|
|
})
|