This doc describes Hokusai commands in detail.
List all available commands by:
hokusai tree
Learn more about a command using --help
:
hokusai --help
hokusai {command} --help
Run a command with --verbose
to print more information about what Hokusai is doing under the cover (e.g. shelling out to kubectl).
Also, use Hokusai's interactive console:
hokusai console
In the console, tab to autocomplete commands. :help
for help.
These commands are global, as in, they are not specific to a project. They can be run in any directory on user's local.
-
hokusai configure
- Install and configure kubectl. Rely on config from~/hokusai.yml
(the global configuration file). User-specified values in command line options (e.g. kubectl-dir) supercede corresponding values in~/.hokusai.yml
. Merge command line options into~/.hokusai.yml
.~/.hokusai.yml
of course would not exist at first. The org admin is expected to prepare an org-wide version which users can then obtain by:HOKUSAI_GLOBAL_CONFIG=s3://bucket/path/to/org/new/config/hokusai.yml hokusai configure
hokusai configure
will read the global config in S3 and write it to~/.hokusai.yml
, creating the file for the first time.Similarly, when an org-wide config (e.g. kubectl version) has changed, the org admin should update S3, and users should re-run the above command to update.
hokusai configure
will overwrite the existing~/.hokusai.yml
.
These commands are project-specific. They should be run from a project's Git repo root. Directories mentioned below are all relative to the root dir.
-
hokusai setup
- Bootstrap Hokusai for a project. Create an AWS Elastic Container Registry (ECR) for the project. Create per-project Hokusai files.The files files are a starting point for development, and you are expected to customize them. If your org (e.g. acme) has templates for these files on Github, say for a Rails project, pull them down by:
hokusai setup --template-remote git@github.com:acme/hokusai-templates.git --template-dir rails
-
hokusai check
- Check that Hokusai dependencies are correctly installed and configured for the current project.
hokusai dev
- Interact with the development environment defined in ./hokusai/development.yml.hokusai dev start
- Start the development environment.hokusai dev stop
- Stop the development environment, but do not delete container filesystems.hokusai dev status
- Print the status of the development environment.hokusai dev logs
- Print logs from the development environment.hokusai dev run
- Run a command in the development environment's main container (one named by 'project-name' as defined in ./hokusai/config.yml).hokusai dev clean
- Stop the development environment, and remove container filesystems.
hokusai test
- Start the test environment defined./hokusai/test.yml
. Exit with the return code of the test command.hokusai build
- Build the docker image defined in ./hokusai/build.yml.
hokusai registry
- Interact with the project's ECR registry.-
hokusai registry push
- Build and push an image to registry. Image tag by default is the SHA1 of current Git branch's HEAD (i.e.git rev-parse HEAD
). Can be overridden with--tag
(although not recommended because SHA1 allows you to map between tags in the registry with theimage
field in the project's Kubernetes pod's spec).A
latest
tag is also created. This tag should not be referenced in any Kubernetes spec. It is meant to serve as a pointer, referenced byhokusai staging/production create
command.The command aborts upon any of the following conditions:
- The working directory is not clean (there are uncommitted changes)
- The working directory contains Git-ignored files (i.e. specified in
.gitignore
file) - The registry already contains the specified tag
These conditional checks are safeguards. Docker image build copies the entire working directory into the container image. When building an image locally, files (e.g.
.env
) can be un-expectedly included and then persisted in the registry, and the image might be used in production! -
hokusai registry images
- List tags in the registry.
-
-
hokusai [staging|production]
- Interact with Kubernetes resources defined in ./hokusai/staging.yml or ./hokusai/production.yml.-
hokusai [staging|production] create
- Create the resources. -
hokusai [staging|production] update
- Update the resources. -
hokusai [staging|production] delete
- Delete the resources. -
hokusai [staging|production] status
- Print the resources. -
hokusai [staging|production] deploy
- Update project's Kubernetes Deployment(s) to reference a certain Docker image tag, and also update the alias Docker image tags (i.e.staging
orproduction
) to point to the deployed Docker image. Patch each Deployment'sapp.kubernetes.io/version
label. Use 2nd half of the Docker image digest as the label's value. -
hokusai [staging|production] [refresh|restart]
- Re-create project's Deployment(s) containers (without changing their Docker image reference). -
hokusai [staging|production] env
- Interact with the application's runtime environment (i.e. project's Kubernetes ConfigMap).hokusai [staging|production] env get
- Print environment variables.hokusai [staging|production] env set
- Set environment variables.hokusai [staging|production] env unset
- Remove environment variables.
Note on
set
andunset
: To have the change take effect, runhokusai [staging|production] refresh
. It re-creates the project Deployment's containers. This is necesssary because Kubernetes does not propogate ConfigMap changes to existing containers. -
hokusai [staging|production] run
- Launch a container and run a given command. Exit with the status code of the command. Useful forrake
tasks, etc. If your command string contains whitespace, single quote it. If your command is interactive, use--tty
flag to attach your terminal (e.g.hokusai production run --tty 'bundle exec rails c'
). -
hokusai [staging|production] logs
- Print the logs from application containers.
-
Review apps can be created and managed with hokusai review_app
.
Please see Review App reference.
hokusai pipeline
- Interact with project's' staging -> production pipeline.hokusai pipeline gitdiff
- Print a diff between the deployed production Git tag and the deployed staging Git tag.hokusai pipeline gitlog
- Print a git log comparing the Git tags deployed on production vs staging, to see what commits are going to be promoted to production.hokusai pipeline gitcompare --org-name <your org name on Github>
- Print a Github URL for staging/production Git comparison.hokusai pipeline promote
- Update project's Deployment(s) in production to use the same Docker image tag that is being used in staging. Updateproduction
Docker image tag to point to the same Docker image. Updateapp.kubernetes.io/version
label, as mentioned above.
hoksuai [staging|production] deploy
or hokusai pipeline promote
perform the following:
- Select all of the project's Deployments (those matching label selectors "app={project_name},layer=application").
- If
--migration
command is specified, run it. If the command fails, exit with the return code of the command. - If
pre-deploy
hook command if specified, run it. If the command fails, exit with the return code of the command. - Patch the Deployment's containers with the new Docker image tag.
- Wait for the Deployment to roll out. If rollout does not complete within
--timeout
minutes (default 10), runkubectl rollout undo
to roll all Deployments back automatically, then exit with1
. - If
post-deploy
hook command is specified, run it. If it fails, print a warning and continue. - Push deployment Docker tags to the registry. If it fails, print a warning and continue.
- If
git-remote
is specified in./hokusai/config.yml
, push deployment Git tags to Github. If it fails, print a warning and continue. - Finally, exit
0
if all steps were successful. If any of steps6
,7
or8
failed, exit with1
.