Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ssl command to download mkcert and generate ssl certificates #465

Merged
merged 45 commits into from
May 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
480f504
Add ssl command to download mkcert and generate ssl certificates
shadyvb Apr 22, 2022
3b1dd4f
Add link to install mkcert after errors installing it
shadyvb Apr 25, 2022
824746e
Remove redundant return statement
shadyvb Apr 25, 2022
901b3b9
Improve logging around errors with ssl
shadyvb Apr 26, 2022
afad00a
Remove redundant output
shadyvb Apr 26, 2022
f2786f9
Removed duplicate handling of get_mkcert_binary()
shadyvb Apr 26, 2022
9441243
Fix docblock
shadyvb Apr 26, 2022
26494bd
:nail_care: Fix CS
shadyvb Apr 26, 2022
b0bb233
Programmatically create SSL certificate and use with Traefik
shadyvb Apr 23, 2022
1be8adf
Allow custom domain name/tld from #341
shadyvb Apr 26, 2022
60baaf5
Fix function args
shadyvb Apr 23, 2022
aa942fc
Fix an error with the run command
shadyvb Apr 27, 2022
5c025de
Skip verifying https for S3 requests
shadyvb Apr 27, 2022
97e4ce9
Try to fix s3 bucket/path mapping
shadyvb Apr 27, 2022
cfec957
Better detect WSL environment
shadyvb Apr 28, 2022
9827897
Restart the proxy container after generating a certificate
shadyvb May 3, 2022
7f36778
Add support for extra custom domains
shadyvb May 3, 2022
af3b6c0
Stop starting if domain has changed to avoid orphan containers
shadyvb May 3, 2022
859114c
Only attempt to restart the proxy container if it is running
shadyvb May 3, 2022
e28a24a
Check if secure is set to false to avoid generating SSL certificate
shadyvb May 3, 2022
e259410
Revert "Check if secure is set to false to avoid generating SSL certi…
shadyvb May 3, 2022
e20718a
:nail_care: CS polish
shadyvb May 3, 2022
578c219
Install mkcert for tests
shadyvb May 3, 2022
4091cad
Add note on mkcert installation url and location
shadyvb May 3, 2022
b50194c
More verbose output on detected os arch
shadyvb May 3, 2022
6b9708f
Fix arch detection for linux
shadyvb May 3, 2022
ef984c4
Fix missing name/tld config
shadyvb May 3, 2022
a3d42f8
Fix missing domains config key
shadyvb May 3, 2022
ce9fb0c
Merge remote-tracking branch 'origin/master' into product-dev-987/ssl…
shadyvb May 3, 2022
2a73d9f
Test connectivity to site in CI
shadyvb May 3, 2022
81ab150
Add aux service URLs to generated certificate
shadyvb May 4, 2022
90ce957
Fix S3 and Tachyon issues with bucket path
shadyvb May 4, 2022
4e6fd76
Add a warning for missing hosts entries
shadyvb May 4, 2022
7c0a020
Fix indentation
shadyvb May 4, 2022
8a79a58
Remove relative path use in traefik config
shadyvb May 4, 2022
2634b85
Fix generation of hosts entries note
shadyvb May 4, 2022
0d6430e
Fix generation of cert around default domain
shadyvb May 4, 2022
6c187a1
Less testing output
shadyvb May 4, 2022
bd8eabc
Do not generate SSL for altis.dev
shadyvb May 4, 2022
37518b7
More efficient domain selection
shadyvb May 4, 2022
b164550
Correct typo
shadyvb May 4, 2022
72c6318
Add traefik.domain label for future multi-instance SSL generation
shadyvb May 4, 2022
b008194
Return instead of exit
shadyvb May 5, 2022
4e26c8f
Document custom domains and SSL command features
shadyvb May 5, 2022
2f11c98
Move SSL generation out of experimental section
shadyvb May 6, 2022
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
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@ before_script:
- cd $HOME/test-root && composer require -W "$ALTIS_PACKAGE:dev-${TRAVIS_PULL_REQUEST_BRANCH:-$TRAVIS_BRANCH} as `jq \".\\\"packages-dev\\\"[] | select (.name==\\\"$ALTIS_PACKAGE\\\") | .version\" composer.lock | sed -e 's/\"//g;/^dev/q;s/\$/9/'`"

script:
- cd $HOME/test-root && composer server ssl install
- cd $HOME/test-root && composer server start
- cd $HOME/test-root && composer server db info
- cd $HOME/test-root && composer server db exec -- "select * from wp_site;"
- cd $HOME/test-root && composer server status
- cd $HOME/test-root && composer server exec -- ls -al
- cd $HOME/test-root && composer server cli site list
- cd $HOME/test-root && composer server start --xdebug=debug,profile
- curl https://test-root.altis.dev/ | grep '<title>'
- cd $HOME/test-root && composer server exec printenv | grep XDEBUG_MODE=debug,profile
- curl -XGET https://test-root.altis.dev/webgrind/ | grep '<title>webgrind</title>'
- cd $HOME/test-root && composer server stop --clean
Expand Down
6 changes: 3 additions & 3 deletions docker/conf/traefik.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ insecureSkipVerify = true
[entryPoints.https]
address = ":443"
[entryPoints.https.tls]
[[entryPoints.https.tls.certificates]]
certFile = "/etc/traefik/sni/cert/altis.pem"
keyFile = "/etc/traefik/sni/key/altis.pem"
[entryPoints.https.tls.defaultCertificate]
certFile = "/etc/traefik/ssl-cert.pem"
keyFile = "/etc/traefik/ssl-key.pem"

[web]
address = ":8080"
Expand Down
7 changes: 3 additions & 4 deletions docker/proxy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ services:
image: traefik:1.7
container_name: altis-proxy
volumes:
- "$PWD/conf/traefik.toml:/etc/traefik/traefik.toml"
- "$PWD/ssl.cert:/etc/traefik/ssl.cert"
- "$PWD/ssl.key:/etc/traefik/ssl.key"
- "$PWD/sni:/etc/traefik/sni"
- "$PWD/altis/local-server/docker/conf/traefik.toml:/etc/traefik/traefik.toml"
- "$PWD/ssl-cert.pem:/etc/traefik/ssl-cert.pem"
- "$PWD/ssl-key.pem:/etc/traefik/ssl-key.pem"
- /var/run/docker.sock:/var/run/docker.sock
ports:
- '8080:8080'
Expand Down
139 changes: 0 additions & 139 deletions docker/sni/cert/altis.pem

This file was deleted.

28 changes: 0 additions & 28 deletions docker/sni/key/altis.pem

This file was deleted.

57 changes: 42 additions & 15 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,45 @@ Navigate your shell to your project's directory. You should already have install

### Experimental Features

#### Mutagen

You may find that file sharing performance or server response times are slower than you would like on Windows or MacOS. Local Server provides an experimental integration with [Mutagen](https://mutagen.io/) to resolve this.

See the [Mutagen set up guide for detailed instructions on how to install and run it](./mutagen-file-sharing.md).

#### Subdomain and Custom domains in multisites
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want this under experimental features? Custom domains / codespaces perhaps but I think the SSL stuff itself doesn't need to be considered experimental as we need it to work for the default TLD at the very least.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's experimental in the sense that it is tied to custom domains which is experimental 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, and we might want to remove it altogether in favor of Traefik managing it on its own, given the centralization needed. I'm writing the issue around that that would explain my suggested approach.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See #475

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it’s fine to not list it as experimental personally, codespaces definitely will be to start with

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@roborourke Updated docs in 2f11c98 , should be ready for a final review.


Altis v12 introduces support for Subdomain multisites and Custom domains, where projects can choose custom domains for their local environments, instead of being locked to the altis.dev domain. This is in part facilitated by the new SSL certificate generation features introduced in Altis v12.

The subdomain / domain *optional* config options can be configured as follows:

```json
{
"extra": {
"altis": {
"modules": {
"local-server": {
"name": "my-project",
"tld": "my-company.local",
"domains": [
"domain1.com",
"domain2.com",
],
}
}
}
}
}
```

* `name` - Project name, used as the subdomain of the primary site, eg: `my-project`
* `tld` - TLD of the project, eg: `my-company.local`
* `domains` - Custom domains used by the project, either for main or sub sites.

Note: Altis does not manage the host entries for subdomains or custom domains, you'll need to manage those manually, via editing `/etc/hosts` in Linux / macOS, or `C:\Windows\System32\Drivers\etc\hosts` in Windows. Altis however tries to detect if those entries do not exist, and outputs the necessary configurations to add to your `hosts` file.

Note: Before *updating* the custom domain configuration parameters, ensure that you've destroyed existing containers first before applying your changes, otherwise you'll be leaving orphan containers from the previous configuration.

## Starting the Local Server

To start the Local Server, run `composer server`. The first time you run this it will download all the necessary Docker images.
Expand All @@ -40,23 +75,11 @@ Visiting your site's URL should now work. Visit `/wp-admin/` and login with the

> [If the server does not start for any reason take a look at the troubleshooting guide](./troubleshooting.md)

The subdomain used for the project can be configured via the `modules.local-server.name` setting:
### Multisite Subdomains / Custom domains support

```json
{
"extra": {
"altis": {
"modules": {
"local-server": {
"name": "my-project"
}
}
}
}
}
```
Altis v12 introduced experimental support for multisite subdomains and custom domains. In order to support custom (sub)domains, Altis is using [`mkcert`](https://github.com/FiloSottile/mkcert) to generate SSL certificates based on a custom generated Root Certificate Authority that is uniquely-generated and trusted on the host machine upon installation. This allows Altis local-server to generate local SSL certificates that is automatically trusted, which provides a convenient and seamless local development experience.

**Multisite Subdomains:** Currently on local-server subdomains aren't supported. Subsites must use subdirectories.
Note: Altis local-server automatically collects domains names to issue the SSL certificate for, based on Altis configuration in `composer.json`, namely the `altis.modules.local-server` tree, specifically the `name`, `tld`, and `domains` config parameteres.

## Available Commands

Expand All @@ -70,6 +93,10 @@ The subdomain used for the project can be configured via the `modules.local-serv
* `composer server destroy [--clean]` - Stops and destroys all containers.
* `--clean` will also destroy the proxy container, only use this if you have no other instances of Local Server
* `composer server status` - Displays the status of all containers.
* `composer server ssl` - Shows the status of local-server SSL certificate.
* `composer server ssl install` - Install mkcert locally and set it up to prepare for SSL generation.
* `composer server ssl generate custom-domain.com` - (re)generates the local-server SSL certificarte including `custom-domain.com`
* `composer server ssl exec -- [<command>]` - Execute custom `mkcert` commands, eg: `-uninstall` to revoke the root CA
* `composer server logs <service>` - Tail the logs from a given service, defaults to `php`, available options are `nginx`, `php`, `db`, `redis`, `cavalcade`, `tachyon`, `s3` and `elasticsearch`.
* `composer server shell` - Logs in to the PHP container.
* `composer server cli -- <command>` - Runs a WP CLI command, you should omit the 'wp' for example `composer server cli -- info`
Expand Down
Loading