Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 18 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ bash <(curl -s \
-v ~/.config/k3d/kubeconfig-gitops-playground.yaml:/home/.kube/config \
--net=host \
ghcr.io/cloudogu/gitops-playground --yes --argocd --ingress --base-url=http://localhost
# More IDP-features: --mailhog --monitoring --vault=dev --cert-manager
# More IDP-features: --mail --monitoring --vault=dev --cert-manager
# More features for developers: --jenkins --registry --content-examples
```

Expand Down Expand Up @@ -425,19 +425,19 @@ That is, if you pass a param via CLI, for example, it will overwrite the corresp

###### Mail

| CLI | Config | Default | Type | Description |
|-----|--------|---------|------|-------------|
| `--mailhog, --mail` | `features.mail.mailhog` | `false` | Boolean | Installs Mailhog as email testing tool |
| `--mailhog-url` | `features.mail.mailhogUrl` | `''` | String | The url of your external mailhog |
| `--smtp-address` | `features.mail.smtpAddress` | `''` | String | SMTP server address |
| `--smtp-port` | `features.mail.smtpPort` | `null` | Integer | SMTP server port |
| `--smtp-user` | `features.mail.smtpUser` | `''` | String | SMTP username |
| `--smtp-password` | `features.mail.smtpPassword` | `''` | String | SMTP password |
| `--mailhog-image` | `features.mail.helm.image` | `'ghcr.io/cloudogu/mailhog:v1.0.1'` | String | Mailhog container image |
| - | `features.mail.helm.chart` | `'mailhog'` | String | Name of the Helm chart |
| CLI | Config | Default | Type | Description |
|-----|------------------------------|---------|------|-------------------------------------------------------------|
| `--mail` | `features.mail.mailServer` | `false` | Boolean | Installs a dedicated mail server |
| `--mail-url` | `features.mail.mailUrl` | `''` | String | The url of the mail server's frontend |
| `--smtp-address` | `features.mail.smtpAddress` | `''` | String | SMTP server address |
| `--smtp-port` | `features.mail.smtpPort` | `null` | Integer | SMTP server port |
| `--smtp-user` | `features.mail.smtpUser` | `''` | String | SMTP username |
| `--smtp-password` | `features.mail.smtpPassword` | `''` | String | SMTP password |
| `--mail-image` | `features.mail.helm.image` | `'ghcr.io/cloudogu/mailhog:v1.0.1'` | String | Container image to use for the mail server |
| - | `features.mail.helm.chart` | `'mailhog'` | String | Name of the Helm chart |
| - | `features.mail.helm.repoURL` | `'https://codecentric.github.io/helm-charts'` | String | Repository url from which the Helm chart should be obtained |
| - | `features.mail.helm.version` | `'5.0.1'` | String | The version of the Helm chart to be installed |
| - | `features.mail.helm.values` | `[:]` | Map | Helm values of the chart |
| - | `features.mail.helm.version` | `'5.0.1'` | String | The version of the Helm chart to be installed |
| - | `features.mail.helm.values` | `[:]` | Map | Helm values of the chart |

###### Monitoring

Expand Down Expand Up @@ -661,7 +661,7 @@ It is possible to deploy `Ingress` objects for all components. You can either
--argocd-url https://argocd.example.com
--grafana-url https://grafana.example.com
--vault-url https://vault.example.com
--mailhog-url https://mailhog.example.com
--mail-url https://mail.example.com
--petclinic-base-domain petclinic.example.com
--nginx-base-domain nginx.example.com
```
Expand Down Expand Up @@ -836,18 +836,18 @@ The gitops-playground uses MailHog to showcase notifications.
Alternatively, you can configure an external mailserver.

Note that you can't use both at the same time.
If you set either `--mailhog` or `--mail` parameter, MailHog will be installed
If you set `--mail` parameter, MailHog will be installed
If you set `--smtp-*` parameters, a external Mailserver will be used and MailHog will not be deployed.

##### MailHog
Set the parameter `--mailhog` to enable MailHog.
Set the parameter `--mail` to enable MailHog.

This will deploy MailHog and configure Argo CD and Grafana to send mails to MailHog.
Sender and recipient email addresses can be set via parameters in some applications, e.g. `--grafana-email-from` or `--argocd-email-to-user`.

Parameters:
* `--mailhog`: Activate MailHog as internal Mailserver
* `--mailhog-url`: Specify domain name (ingress) under which MailHog will be served
* `--mail`: Activate MailHog as internal Mailserver
* `--mail-url`: Specify domain name (ingress) under which MailHog will be served

##### External Mailserver
If you want to use an external Mailserver you can set it with these parameters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ argo-cd:
<#if config.features.mail.smtpUser?has_content>username: $email-username</#if>
<#if config.features.mail.smtpPassword?has_content>password: $email-password</#if>
<#else>
host: mailhog.${config.application.namePrefix}monitoring.svc.cluster.local
host: mail.${config.application.namePrefix}monitoring.svc.cluster.local
port: 1025
</#if>
from: ${config.features.argocd.emailFrom}
Expand Down
8 changes: 4 additions & 4 deletions docs/configuration.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -420,13 +420,13 @@
"additionalProperties" : false,
"description" : "Common Config parameters for the Helm package manager: Name of Chart (chart), URl of Helm-Repository (repoURL) and Chart Version (version). Note: These config is intended to obtain the chart from a different source (e.g. in air-gapped envs), not to use a different version of a helm chart. Using a different helm chart or version to the one used in the GOP version will likely cause errors."
},
"mailhog" : {
"mailServer" : {
"type" : [ "boolean", "null" ],
"description" : "Installs MailHog as Mail server."
"description" : "Installs a dedicated mail server."
},
"mailhogUrl" : {
"mailUrl" : {
"type" : [ "string", "null" ],
"description" : "Sets url for MailHog"
"description" : "Sets url for the mail server frontend"
},
"smtpAddress" : {
"type" : [ "string", "null" ],
Expand Down
6 changes: 3 additions & 3 deletions docs/developers.md
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ docker run --rm -t -u $(id -u) \
--net=host \
${GOP_IMAGE} -x \
--yes --argocd --ingress --base-url=http://localhost \
--vault=dev --monitoring --mailhog --cert-manager \
--vault=dev --monitoring --mail --cert-manager \
--create-image-pull-secrets \
--registry-url=localhost:30000 \
--registry-path=registry \
Expand All @@ -558,7 +558,7 @@ docker run --rm -t -u $(id -u) \
--registry-proxy-password=Proxy12345 \
--registry-username-read-only=RegistryRead \
--registry-password-read-only=RegistryRead12345 \
--mailhog-image=localhost:30000/proxy/mailhog:latest \
--mail-image=localhost:30000/proxy/mailhog:latest \
--vault-image=localhost:30000/proxy/vault:latest \
--config-file=/home/two-registries.yaml

Expand Down Expand Up @@ -806,7 +806,7 @@ docker run --rm -it -u $(id -u) \
--net=host \
gitops-playground:dev --argocd --monitoring --vault=dev -x --yes \
--argocd-url argocd.localhost --grafana-url grafana.localhost --vault-url vault.localhost \
--mailhog-url mailhog.localhost --petclinic-base-domain petclinic.localhost \
--mail-url mail.localhost --petclinic-base-domain petclinic.localhost \
--nginx-base-domain nginx.localhost
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import com.cloudogu.gitops.jenkins.*
import com.cloudogu.gitops.kubernetes.api.HelmClient
import com.cloudogu.gitops.kubernetes.api.K8sClient
import com.cloudogu.gitops.utils.*
import groovy.transform.CompileStatic
import groovy.util.logging.Slf4j
import io.micronaut.context.ApplicationContext
import jakarta.inject.Provider
Expand All @@ -32,37 +33,36 @@ import jakarta.inject.Provider
* Yes, redundant and not beautiful, but not using dependency injection is worse.
*/
@Slf4j
@CompileStatic
class GitopsPlaygroundCliMainScripted {

static void main(String[] args) throws Exception {
new GitopsPlaygroundCliMain().exec(args, GitopsPlaygroundCliScripted.class)
new GitopsPlaygroundCliMain().exec(args, GitopsPlaygroundCliScripted)
}

static class GitopsPlaygroundCliScripted extends GitopsPlaygroundCli {

protected void register(Config config, ApplicationContext context) {
super.register(config, context)

def fileSystemUtils = new FileSystemUtils()
def executor = new CommandExecutor()
def networkingUtils = new NetworkingUtils()
def k8sClient = new K8sClient(executor, fileSystemUtils, new Provider<Config>() {
FileSystemUtils fileSystemUtils = new FileSystemUtils()
CommandExecutor executor = new CommandExecutor()
NetworkingUtils networkingUtils = new NetworkingUtils()

K8sClient k8sClient = new K8sClient(executor, fileSystemUtils, new Provider<Config>() {
@Override
Config get() {
return config
}
})
def helmClient = new HelmClient(executor)

def httpClientFactory = new HttpClientFactory()

def gitRepoFactory = new GitRepoFactory(config, fileSystemUtils)

def helmStrategy = new HelmStrategy(config, helmClient)
HelmClient helmClient = new HelmClient(executor)
HttpClientFactory httpClientFactory = new HttpClientFactory()
GitRepoFactory gitRepoFactory = new GitRepoFactory(config, fileSystemUtils)
HelmStrategy helmStrategy = new HelmStrategy(config, helmClient)
GitHandler gitHandler = new GitHandler(config, helmStrategy, fileSystemUtils, k8sClient, networkingUtils)

def gitHandler = new GitHandler(config, helmStrategy, fileSystemUtils, k8sClient, networkingUtils)

def jenkinsApiClient = new JenkinsApiClient(config,
JenkinsApiClient jenkinsApiClient = new JenkinsApiClient(config,
httpClientFactory.okHttpClientJenkins(config))

context.registerSingleton(k8sClient)
Expand All @@ -71,16 +71,14 @@ class GitopsPlaygroundCliMainScripted {
context.registerSingleton(new Destroyer([
new ArgoCDDestructionHandler(config, k8sClient, gitRepoFactory, helmClient, fileSystemUtils, gitHandler),
new ScmmDestructionHandler(config),
new JenkinsDestructionHandler(new JobManager(jenkinsApiClient), config, new GlobalPropertyManager(jenkinsApiClient))
new JenkinsDestructionHandler(new JobManager(jenkinsApiClient), config, new GlobalPropertyManager(jenkinsApiClient)),
]))
} else {
def deployer = new Deployer(config, new ArgoCdApplicationStrategy(config, fileSystemUtils, gitRepoFactory, gitHandler), helmStrategy)

def airGappedUtils = new AirGappedUtils(config, gitRepoFactory, fileSystemUtils, helmClient, gitHandler)

def jenkins = new Jenkins(config, executor, fileSystemUtils, new GlobalPropertyManager(jenkinsApiClient),
Deployer deployer = new Deployer(config, new ArgoCdApplicationStrategy(config, fileSystemUtils, gitRepoFactory, gitHandler), helmStrategy)
AirGappedUtils airGappedUtils = new AirGappedUtils(config, gitRepoFactory, fileSystemUtils, helmClient, gitHandler)
Jenkins jenkins = new Jenkins(config, executor, fileSystemUtils, new GlobalPropertyManager(jenkinsApiClient),
new JobManager(jenkinsApiClient), new UserManager(jenkinsApiClient),
new PrometheusConfigurator(jenkinsApiClient), helmStrategy, k8sClient, networkingUtils,gitHandler)
new PrometheusConfigurator(jenkinsApiClient), helmStrategy, k8sClient, networkingUtils, gitHandler)

// make sure the order of features is in same order as the @Order values
context.registerSingleton(new Application(config, [
Expand All @@ -90,13 +88,13 @@ class GitopsPlaygroundCliMainScripted {
new ArgoCD(config, k8sClient, helmClient, fileSystemUtils, gitRepoFactory, gitHandler),
new Ingress(config, fileSystemUtils, deployer, k8sClient, airGappedUtils, gitHandler),
new CertManager(config, fileSystemUtils, deployer, k8sClient, airGappedUtils, gitHandler),
new Mailhog(config, fileSystemUtils, deployer, k8sClient, airGappedUtils, gitHandler),
new PrometheusStack(config, fileSystemUtils, deployer, k8sClient, airGappedUtils, gitRepoFactory, gitHandler),
new Mail(config, fileSystemUtils, deployer, k8sClient, airGappedUtils, gitHandler),
new Monitoring(config, fileSystemUtils, deployer, k8sClient, airGappedUtils, gitRepoFactory, gitHandler),
new ExternalSecretsOperator(config, fileSystemUtils, deployer, k8sClient, airGappedUtils, gitHandler),
new Vault(config, fileSystemUtils, k8sClient, deployer, airGappedUtils, gitHandler),
new ContentLoader(config, k8sClient, gitRepoFactory, jenkins, gitHandler),
]))
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ class ApplicationConfigurator {
if (newConfig.features.secrets.vault.mode)
newConfig.features.secrets.active = true

if (newConfig.features.mail.smtpAddress || newConfig.features.mail.mailhog)
if (newConfig.features.mail.smtpAddress || newConfig.features.mail.mailServer)
newConfig.features.mail.active = true
if (newConfig.features.mail.smtpAddress && newConfig.features.mail.mailhog) {
newConfig.features.mail.mailhog = false
log.warn("Enabled both external Mailserver and MailHog! Implicitly deactivating MailHog")
if (newConfig.features.mail.smtpAddress && newConfig.features.mail.mailServer) {
newConfig.features.mail.mailServer = false
log.warn("Enabled both external Mailserver and in-cluster Mailserver! Implicitly deactivating in-cluster mailserver")
}

if (newConfig.features.ingress.active && !newConfig.application.baseUrl) {
Expand Down Expand Up @@ -195,9 +195,9 @@ class ApplicationConfigurator {
argocd.url = injectSubdomain("argocd", baseUrl, urlSeparatorHyphen)
log.debug("Setting ArgoCD URL ${argocd.url}")
}
if (mail.mailhog && !mail.mailhogUrl) {
mail.mailhogUrl = injectSubdomain('mailhog', baseUrl, urlSeparatorHyphen)
log.debug("Setting Mail URL ${mail.mailhogUrl}")
if (mail.mailServer && !mail.mailUrl) {
mail.mailUrl = injectSubdomain('mail', baseUrl, urlSeparatorHyphen)
log.debug("Setting Mail URL ${mail.mailUrl}")
}
if (monitoring.active && !monitoring.grafanaUrl) {
monitoring.grafanaUrl = injectSubdomain('grafana', baseUrl, urlSeparatorHyphen)
Expand Down
17 changes: 8 additions & 9 deletions src/main/groovy/com/cloudogu/gitops/config/Config.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import com.fasterxml.jackson.databind.ser.BeanSerializerModifier
import com.fasterxml.jackson.dataformat.yaml.YAMLMapper
import groovy.transform.MapConstructor
import jakarta.inject.Singleton
import org.apache.http.client.CredentialsProvider
import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider
import picocli.CommandLine.Command
import picocli.CommandLine.Mixin
import picocli.CommandLine.Option
Expand Down Expand Up @@ -498,13 +496,14 @@ class Config {

Boolean active = false

@Option(names = ['--mailhog', '--mail'], description = MAILHOG_ENABLE_DESCRIPTION, scope = ScopeType.INHERIT)
@JsonPropertyDescription(MAILHOG_ENABLE_DESCRIPTION)
Boolean mailhog = false
@Option(names = ['--mail'], description = MAILSERVER_ENABLE_DESCRIPTION, scope = ScopeType.INHERIT)
@JsonPropertyDescription(MAILSERVER_ENABLE_DESCRIPTION)
Boolean mailServer = false

@Option(names = ['--mailhog-url'], description = MAILHOG_URL_DESCRIPTION)
@JsonPropertyDescription(MAILHOG_URL_DESCRIPTION)
String mailhogUrl = ''

@Option(names = ['--mail-url'], description = MAIL_URL_DESCRIPTION)
@JsonPropertyDescription(MAIL_URL_DESCRIPTION)
String mailUrl = ''

@Option(names = ['--smtp-address'], description = SMTP_ADDRESS_DESCRIPTION)
@JsonPropertyDescription(SMTP_ADDRESS_DESCRIPTION)
Expand All @@ -530,7 +529,7 @@ class Config {
version: '5.0.1')

static class MailHelmSchema extends HelmConfigWithValues {
@Option(names = ['--mailhog-image'], description = HELM_CONFIG_IMAGE_DESCRIPTION)
@Option(names = ['--mail-image'], description = HELM_CONFIG_IMAGE_DESCRIPTION)
@JsonPropertyDescription(HELM_CONFIG_IMAGE_DESCRIPTION)
String image = 'ghcr.io/cloudogu/mailhog:v1.0.1'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ interface ConfigConstants {
String VAULT_URL_DESCRIPTION = 'Sets url for vault ui'

String MAIL_DESCRIPTION = 'Config parameters for mail servers'
String MAILHOG_URL_DESCRIPTION = 'Sets url for MailHog'
String MAILHOG_ENABLE_DESCRIPTION = 'Installs MailHog as Mail server.'
String MAIL_URL_DESCRIPTION = 'Sets url for the mail server frontend'
String MAILSERVER_ENABLE_DESCRIPTION = 'Installs a dedicated mail server.'

// group external Mailserver
String SMTP_ADDRESS_DESCRIPTION = 'Sets smtp port of external Mailserver'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,26 @@ import com.cloudogu.gitops.features.git.GitHandler
import com.cloudogu.gitops.utils.AirGappedUtils
import com.cloudogu.gitops.utils.FileSystemUtils
import com.cloudogu.gitops.kubernetes.api.K8sClient
import groovy.transform.CompileStatic
import groovy.util.logging.Slf4j
import io.micronaut.core.annotation.Order
import jakarta.inject.Singleton
import org.springframework.security.crypto.bcrypt.BCrypt


@Slf4j
@Singleton
@Order(200)
class Mailhog extends Feature implements FeatureWithImage {
@CompileStatic
class Mail extends Feature implements FeatureWithImage {

static final String HELM_VALUES_PATH = "argocd/cluster-resources/apps/mailhog/templates/mailhog-helm-values.ftl.yaml"
final static private String HELM_VALUES_PATH = 'argocd/cluster-resources/apps/mail/templates/mail-helm-values.ftl.yaml'
final private String password

String namespace = "${config.application.namePrefix}monitoring"
Config config
K8sClient k8sClient

private String username
private String password

Mailhog(
Mail(
Config config,
FileSystemUtils fileSystemUtils,
DeploymentStrategy deployer,
Expand All @@ -45,23 +44,21 @@ class Mailhog extends Feature implements FeatureWithImage {
this.gitHandler = gitHandler
}


@Override
boolean isEnabled() {
return config.features.mail.mailhog
return config.features.mail.mailServer
}

@Override
void enable() {
String bcryptMailhogPassword = BCrypt.hashpw(password, BCrypt.gensalt(4))

addHelmValuesData("passwordCrypt", bcryptMailhogPassword)
addHelmValuesData("mail", [
addHelmValuesData('passwordCrypt', bcryptMailhogPassword)
addHelmValuesData('mail', [
// Note that passing the URL object here leads to problems in Graal Native image, see Git history
host: config.features.mail.mailhogUrl ? new URL(config.features.mail.mailhogUrl).host : "",
host: config.features.mail.mailUrl ? new URL(config.features.mail.mailUrl).host : '',
])

def helmConfig = config.features.mail.helm
deployHelmChart('mailhog', 'mailhog', namespace, helmConfig, HELM_VALUES_PATH, config)
deployHelmChart('mailhog', 'mailhog', namespace, config.features.mail.helm, HELM_VALUES_PATH, config)
}
}
}
Loading