Commit Graph

1377 Commits

Author SHA1 Message Date
Donal McBreen 10b8c826d8 Merge pull request #755 from basecamp/lock-less
Lock less
2024-05-21 12:33:45 +01:00
Donal McBreen 187861fa60 Space not tab 2024-05-21 12:20:19 +01:00
Donal McBreen 5ff1203c80 Always lock before pre-deploy hook 2024-05-21 12:02:16 +01:00
Donal McBreen 0e73f02743 Split lock and connection setup
Allow run the pre-connect hook before the first SSH command is executed,
but only run the locking in `with_lock` blocks.
2024-05-21 12:02:16 +01:00
Donal McBreen 83d0078525 Confirm outside mutating 2024-05-21 12:02:16 +01:00
Donal McBreen 96ef0fbc4d Fix merge error 2024-05-21 12:02:16 +01:00
Donal McBreen b12654ccd0 Don't lock until confirmed 2024-05-21 12:02:16 +01:00
Donal McBreen 64f5955444 Don't hold lock on error 2024-05-21 12:02:12 +01:00
Donal McBreen d2a719998a Building doesn't need a deploy lock 2024-05-21 12:01:08 +01:00
Donal McBreen 6a7c90cf4d Only stopping containers locks 2024-05-21 12:01:07 +01:00
Donal McBreen 2c2d94c6d9 Merge pull request #740 from basecamp/remove-healthcheck-step
Remove the healthcheck step
2024-05-21 12:00:25 +01:00
Donal McBreen c62bd1dc31 Merge pull request #815 from basecamp/envify-already-pushes-env
Envify already env pushes
2024-05-21 11:57:55 +01:00
Donal McBreen a83df9e135 Merge pull request #620 from mlitwiniuk/allow_custom_ports_for_ssh
Allow custom user and port for builder host
2024-05-21 11:49:06 +01:00
Donal McBreen 7b55f4734e Envify already env pushes
`kamal envify` will do `kamal env push` for us, so no need to call it
ourselves during setup.
2024-05-21 11:47:51 +01:00
Donal McBreen 1e296c4140 Update sshkit_with_ext.rb 2024-05-21 11:38:30 +01:00
Donal McBreen 9700e2b3c4 Merge pull request #646 from nickhammond/server/exec
Add in a server exec command for running ad-hoc commands directly on the server
2024-05-21 11:34:20 +01:00
Donal McBreen 706b82baa1 Simplify messages and remove multiple execute error 2024-05-21 10:40:01 +01:00
Donal McBreen fa7e941648 Make SSHKit::Runner::Parallel fail slow
Using a different SSHKit runner doesn't work well, because the group
runner uses the Parallel runner internally. So instead we'll patch its
behaviour to fail slow.

We'll also get it to return all the errors so we can report on all the
hosts that failed.
2024-05-21 09:33:22 +01:00
Donal McBreen 78c0a0ba4b Don't start other roles we have a healthy container
If a primary role container is unhealthy, we might take a while to
timeout the health check poller. In the meantime if we have started the
other roles, they'll be running tow containers.

This could be a problem, especially if they read run jobs as that
doubles the worker capacity which could cause exessive load.

We'll wait for the first primary role container to boot successfully
before starting the other containers from other roles.
2024-05-21 08:37:36 +01:00
Donal McBreen 060e5d2027 Update lib/kamal/cli/server.rb
Co-authored-by: Sijawusz Pur Rahnama <sija@sija.pl>
2024-05-21 08:22:20 +01:00
Nick Hammond 8a4f7163bb Apply suggestions from code review
Co-authored-by: Donal McBreen <dmcbreen@gmail.com>
2024-05-20 11:15:14 -07:00
Donal McBreen ee758d951a Only use barrier when needed, more descriptive info 2024-05-20 12:18:30 +01:00
Donal McBreen bb2ca81d87 Fix rebase method duplication 2024-05-20 12:18:30 +01:00
Donal McBreen 773ba3a5ab Show container logs and healthcheck status on failure 2024-05-20 12:18:30 +01:00
Donal McBreen 5be6fa3b4e Improve comments 2024-05-20 12:18:30 +01:00
Donal McBreen 07c5658396 Remove redundant method 2024-05-20 12:18:30 +01:00
Donal McBreen 0efb5ccfff Remove the healthcheck step
To speed up deployments, we'll remove the healthcheck step.

This adds some risk to deployments for non-web roles - if they don't
have a Docker healthcheck configured then the only check we do is if
the container is running.

If there is a bad image we might see the container running before it
exits and deploy it. Previously the healthcheck step would have avoided
this by ensuring a web container could boot and serve traffic first.

To mitigate this, we'll add a deployment barrier. Until one of the
primary role containers passes its healthcheck, we'll keep the barrier
up and avoid stopping the containers on the non-primary roles.

It the primary role container fails its healthcheck, we'll close the
barrier and shut down the new containers on the waiting roles.

We also have a new integration test to check we correctly handle a
a broken image. This highlighted that SSHKit's default runner will
stop at the first error it encounters. We'll now have a custom runner
that waits for all threads to finish allowing them to clean up.
2024-05-20 12:18:30 +01:00
Donal McBreen 990f1b4413 Merge pull request #798 from basecamp/git-clone
Build from within a git clone by default
2024-05-20 12:18:07 +01:00
Donal McBreen da9428f64d Merge pull request #813 from basecamp/handle-no-env-tags
Don't blow up if there are no env tags
2024-05-20 10:58:11 +01:00
Donal McBreen 17dcaccb6a Don't blow up if there are no env tags 2024-05-20 10:50:07 +01:00
Donal McBreen 448349d0e5 Merge pull request #812 from basecamp/sshkit-1.22.2-minimum
Set sshkit minimum version to 1.22.2
2024-05-20 10:39:17 +01:00
Donal McBreen b6dba57c7d Set sshkit minimum version to 1.22.2
This includes a fix for a bug in the eviction thread that could cause
this error:

```
[ERROR (IOError): Exception while executing on host foo: closed stream]
```

See https://github.com/capistrano/sshkit/pull/534
2024-05-20 10:06:53 +01:00
Donal McBreen 0ea2a2c509 Don't include destination in clone directory
Reusing the clone directory should allow caching of the build context
between deployments to different destinations.
2024-05-20 09:34:42 +01:00
Donal McBreen 307750ff70 Build from within a git clone by default
Docker does not respect the .dockerignore file when building from a tar.

Instead by default we'll make a local clone into a tmp directory and
build from there. Subsequent builds will reset the clone to match the
checkout.

Compared to building directly in the repo, we'll have reproducible
builds.

Compared to using a git archive:
1. .dockerignore is respected
2. We'll have faster builds - docker can be smarter about caching the
build context on subsequent builds from a directory

To build from the repo directly, set the build context to "." in the
config.

If there are uncommitted changes, we'll warn about them either being
included or ignored depending on whether we build from the clone.
2024-05-20 09:30:56 +01:00
Donal McBreen 88947b6a7b Merge pull request #805 from basecamp/env-under-tags
Move env_tags under env key
2024-05-15 11:09:47 +01:00
Donal McBreen f48c227768 Move env_tags under env key
Instead of:

```
env:
  CLEAR_TAG: untagged
env_tags:
  tag1:
    CLEAR_TAG: tagged
```

We'll have:

```
env:
  clear:
    CLEAR_TAG: untagged
  tags:
    tag1:
      CLEAR_TAG: tagged
```
2024-05-15 10:19:22 +01:00
David Heinemeier Hansson f98380ef0c Merge pull request #802 from basecamp/envify-during-setup
Envify during setup
2024-05-14 16:00:28 -07:00
David Heinemeier Hansson 0bc27c10cc Fix tests 2024-05-14 11:59:42 -07:00
David Heinemeier Hansson e58d2f67f2 Fix env template path check and tests 2024-05-14 10:07:31 -07:00
David Heinemeier Hansson 938ac375a1 Only envify if there is a template file available 2024-05-13 17:08:53 -07:00
David Heinemeier Hansson dc1f707a56 Fix test 2024-05-13 17:01:50 -07:00
David Heinemeier Hansson 033f2a3401 Correct invocation 2024-05-13 16:59:50 -07:00
David Heinemeier Hansson 7cac7e6fb0 Envify during setup 2024-05-13 15:18:11 -07:00
Nick Hammond fb58fc0ba6 Add in a server exec command for running ad-hoc commands directly on the server 2024-05-13 14:17:06 -07:00
Donal McBreen 12cad5458a Merge pull request #762 from kryachkov/main
Trim long hostnames
2024-05-10 16:05:27 +01:00
Donal McBreen f8b7f74543 Merge pull request #786 from hundredwatt/add-target-option-to-builder
Add --target option to Builder to support multi-stage Docker builds
2024-05-10 15:15:31 +01:00
Donal McBreen 489d6dbcbb Merge pull request #789 from basecamp/host-tags
Host specific env with tags
2024-05-10 08:08:29 +01:00
Donal McBreen 6d062ce271 Host specific env with tags
Allow hosts to be tagged so we can have host specific env variables.

We might want host specific env variables for things like datacenter
specific tags or testing GC settings on a specific host.

Right now you either need to set up a separate role, or have the app
be host aware.

Now you can define tag env variables and assign those to hosts.

For example:
```
servers:
  - 1.1.1.1
  - 1.1.1.2: tag1
  - 1.1.1.2: tag2
  - 1.1.1.3: [ tag1, tag2 ]
env_tags:
  tag1:
    ENV1: value1
  tag2:
    ENV2: value2
```

The tag env supports the full env format, allowing you to set secret and
clear values.
2024-05-09 16:02:45 +01:00
Jason Nochlin 1e44cc2597 fix rubocop violation 2024-05-08 19:22:25 -06:00
André Falk 63c47eca4c Trim long hostnames
Hostnames longer than 64 characters are not supported by docker
2024-05-07 19:06:39 +02:00