diff --git a/README.md b/README.md index 6d509db..5851559 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,21 @@ The following templates are included. - MariaDB Server - PHPMyAdmin +- **`general-pg`** + Includes all toolchains and apps as the `general` template. Also includes the following services: + - PostgreSQL Server + - pgAdmin 4 + +- **`general-redis`** + Includes all toolchains and apps as the `general` template. Also includes the following services: + - Redis Server + +- **`general-pg-redis`** + Includes all toolchains and apps as the `general` template. Also includes the following services: + - PostgreSQL Server + - Redis Server + - pgAdmin 4 + ## Usage First of all, clone this repository. diff --git a/modules/general/Dockerfile b/modules/general/Dockerfile index 1fa5131..ec7c9e5 100644 --- a/modules/general/Dockerfile +++ b/modules/general/Dockerfile @@ -22,6 +22,9 @@ RUN curl -fsSL https://deb.nodesource.com/setup_18.x | bash - \ # Install Taskfile RUN env GOBIN=/bin go install github.com/go-task/task/v3/cmd/task@latest +# Install staticcheck +RUN env GOBIN=/bin go install honnef.co/go/tools/cmd/staticcheck@latest + # Install Corepack / Yarn RUN corepack enable \ && npm i -g corepack diff --git a/modules/general/main.tf b/modules/general/main.tf index 8ddc5f7..f89de49 100644 --- a/modules/general/main.tf +++ b/modules/general/main.tf @@ -51,7 +51,7 @@ resource "docker_image" "workspace_image" { build { path = "." dockerfile = "./modules/general/Dockerfile" - tag = ["coder-base-general-workspace-image:latest"] + tag = ["coder-base-general-workspace-image"] build_arg = { BASE_IMAGE: var.workspace_base_image } diff --git a/modules/postgres/main.tf b/modules/postgres/main.tf index ac310b6..be69e1f 100644 --- a/modules/postgres/main.tf +++ b/modules/postgres/main.tf @@ -24,7 +24,7 @@ variable "database" { default = "root" } variable "pgadmin_email" { - default = "root@root" + default = "root@root.com" } variable "pgadmin_password" { default = "root" diff --git a/templates/general-pg-redis/main.tf b/templates/general-pg-redis/main.tf new file mode 100644 index 0000000..a003756 --- /dev/null +++ b/templates/general-pg-redis/main.tf @@ -0,0 +1,134 @@ +terraform { + required_providers { + coder = { + source = "coder/coder" + version = "0.4.2" + } + docker = { + source = "kreuzwerker/docker" + version = "~> 2.16.0" + } + } +} + +# ->> Admin parameters ----------------------------------------------------------------------------- + +variable "step2_arch" { + description = <<-EOF + arch: What architecture is your Docker host on? + note: codercom/enterprise-* images are only built for amd64 + EOF + + validation { + condition = contains(["amd64", "arm64", "armv7"], var.step2_arch) + error_message = "Value must be amd64, arm64, or armv7." + } + sensitive = true +} + +variable "step3_OS" { + description = <<-EOF + What operating system is your Coder host on? + EOF + + validation { + condition = contains(["MacOS", "Windows", "Linux"], var.step3_OS) + error_message = "Value must be MacOS, Windows, or Linux." + } + sensitive = true +} + +# <<- Admin parameters ----------------------------------------------------------------------------- + +# ->> Startup parameters --------------------------------------------------------------------------- + +variable "workspace_base_image" { + description = "Which Docker base image would you like to use for your workspace?" + default = "codercom/enterprise-base:ubuntu" + validation { + condition = contains( + ["codercom/enterprise-base:ubuntu", "codercom/code-server:latest"], + var.workspace_base_image) + error_message = "Invalid Docker image!" + } +} + +variable "dotfiles_uri" { + description = <<-EOF + Dotfiles repo URI (optional) + (see https://dotfiles.github.io) + EOF + default = "" +} + +variable "pg_username" { + description = "The default user name for PostgreSQL." + default = "root" +} + +variable "pg_password" { + description = "The default password for PostgreSQL." + default = "root" +} + +variable "pg_database" { + description = "The name of the initial database for PostgreSQL." + default = "root" +} + +variable "pgadmin_email" { + description = "The login email for PgAdmin." + default = "root@root.com" +} + +variable "pgadmin_password" { + description = "The login password for PgAdmin." + default = "root" +} + +variable "redis_enable_persistence" { + description = "Enable Redis data persistence." + default = false +} + + +# <<- Startup parameters --------------------------------------------------------------------------- + +data "coder_workspace" "me" { +} + +resource "docker_network" "internal_network" { + name = "coder-internal-${data.coder_workspace.me.owner}-${data.coder_workspace.me.name}" + driver = "bridge" +} + +module "general" { + source = "./modules/general" + + step2_arch = var.step2_arch + step3_OS = var.step3_OS + workspace_base_image = var.workspace_base_image + dotfiles_uri = var.dotfiles_uri + + docker_network = docker_network.internal_network.name +} + +module "postgres" { + source = "./modules/postgres" + + username = var.pg_username + password = var.pg_password + database = var.pg_database + pgadmin_email = var.pgadmin_email + pgadmin_password = var.pgadmin_password + + docker_network = docker_network.internal_network.name +} + +module "redis" { + source = "./modules/redis" + + enable_persistence = var.redis_enable_persistence + + docker_network = docker_network.internal_network.name +} \ No newline at end of file diff --git a/templates/general-pg/main.tf b/templates/general-pg/main.tf index 628705e..b6bb188 100644 --- a/templates/general-pg/main.tf +++ b/templates/general-pg/main.tf @@ -78,7 +78,7 @@ variable "pg_database" { variable "pgadmin_email" { description = "The login email for PgAdmin." - default = "root@root" + default = "root@root.com" } variable "pgadmin_password" {