-
Notifications
You must be signed in to change notification settings - Fork 482
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Setting env variables in the docker arguments requires having them on the deploy host. Instead we'll add two new commands `kamal env push` and `kamal env delete` which will manage copying the environment as .env files to the remote host. Docker will pick up the file with `--env-file <path-to-file>`. Env files will be stored under `<kamal run directory>/env`. Running `kamal env push` will create env files for each role and accessory, and traefik if required. `kamal envify` has been updated to also push the env files. By avoiding using `kamal envify` and creating the local and remote secrets manually, you can now avoid accessing secrets needed for the docker runtime environment locally. You will still need build secrets. One thing to note - the Docker doesn't parse the environment variables in the env file, one result of this is that you can't specify multi-line values - see moby/moby#12997. We maybe need to look docker config or docker secrets longer term to get around this. Hattip to @kevinmcconnell - this was all his idea.
- Loading branch information
Showing
32 changed files
with
453 additions
and
170 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
require "tempfile" | ||
|
||
class Kamal::Cli::Env < Kamal::Cli::Base | ||
desc "push", "Push the env file to the remote hosts" | ||
def push | ||
mutating do | ||
on(KAMAL.hosts) do | ||
KAMAL.roles_on(host).each do |role| | ||
role_config = KAMAL.config.role(role) | ||
execute *KAMAL.app(role: role).make_env_directory | ||
upload! StringIO.new(role_config.env_file), role_config.host_env_file_path, mode: 400 | ||
end | ||
end | ||
|
||
on(KAMAL.traefik_hosts) do | ||
execute *KAMAL.traefik.make_env_directory | ||
upload! StringIO.new(KAMAL.traefik.env_file), KAMAL.traefik.host_env_file_path, mode: 400 | ||
end | ||
|
||
on(KAMAL.accessory_hosts) do | ||
KAMAL.accessories_on(host).each do |accessory| | ||
accessory_config = KAMAL.config.accessory(accessory) | ||
execute *KAMAL.accessory(accessory).make_env_directory | ||
upload! StringIO.new(accessory_config.env_file), accessory_config.host_env_file_path, mode: 400 | ||
end | ||
end | ||
end | ||
end | ||
|
||
desc "delete", "Delete the env file from the remote hosts" | ||
def delete | ||
mutating do | ||
on(KAMAL.hosts) do | ||
KAMAL.roles_on(host).each do |role| | ||
role_config = KAMAL.config.role(role) | ||
execute *KAMAL.app(role: role).remove_env_file | ||
end | ||
end | ||
|
||
on(KAMAL.traefik_hosts) do | ||
execute *KAMAL.traefik.remove_env_file | ||
end | ||
|
||
on(KAMAL.accessory_hosts) do | ||
KAMAL.accessories_on(host).each do |accessory| | ||
accessory_config = KAMAL.config.accessory(accessory) | ||
execute *KAMAL.accessory(accessory).remove_env_file | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.