0.9.0 • Published 5 years ago

@atomist/k8-automation v0.9.0

Weekly downloads
52
License
Apache-2.0
Repository
github
Last release
5 years ago

@atomist/k8-automation

npm version Docker Pulls

This repository contains automations for deploying applications to Kubernetes using the Atomist API. Currently, deploying Docker images as deployments with optional services and ingress rules is supported.

This project uses the @atomist/automation-client and @atomist/sdm node modules to implement a local client that connects to the Atomist API and executes goals on behalf of a software delivery machine.

Prerequisites

Below are brief instructions on how to get started running this project yourself. If you just want to use the functionality this project provides, see the Atomist documentation.

Atomist workspace

You need an Atomist workspace. If you do not already have an Atomist workspace, you can sign up with Atomist at https://app.atomist.com/. See the Atomist User Guide for detailed instructions on how to sign up with Atomist.

Kubernetes

This automation works with Kubernetes, so you need a Kubernetes cluster with a functioning ingress controller, such as ingress-nginx.

If you do not have access to a Kubernetes cluster, you can create one on your local system using minikube. Once you have minikube running, you can create an ingress controller in the cluster using the ingress add-on.

$ minikube start
$ minikube addons enable ingress

Configuration

You can run k8-automation in either "cluster-wide" mode or "namespace-scoped" mode. In cluster-wide mode, k8-automation is able to deploy and update applications in any namespace but it requires a user with cluster-admin role privileges to install it. If you only have access to admin role privileges in a namespace, you can install k8-automation in namespace-scoped mode, where it will only be able to deploy and update resources in that namespace.

Running

See the Atomist Kubernetes documentation for detailed instructions on using Atomist with Kubernetes. Briefly, if you already have an Atomist workspace, you can run the following commands to create the necessary resources in your Kubernetes cluster. Replace WORKSPACE_ID with your Atomist workspace/team ID and TOKEN with a GitHub token with "read:org" scopes for a user within the GitHub organization linked to your Atomist workspace.

$ kubectl apply --filename=https://raw.githubusercontent.com/atomist/k8-automation/master/assets/kubectl/cluster-wide.yaml
$ kubectl create secret --namespace=k8-automation generic automation \
    --from-literal=config='{"teamIds":["WORKSPACE_ID"],"token":"TOKEN"}'

SDM interface

The KubeDeploy event handler triggers off an SDM Goal with the following properties:

JSON PathValue
fulfillment.name@atomist/k8-automation
fulfillment.methodside-effect
staterequested

In addition, it expects the SDM Goal to have a data property that when parsed as JSON has a kubernetes property whose value is an object with the following properties:

PropertyRequiredDescription
nameYesName of the resources that will be created
environmentYesMust equal the value of the running k8-automation instance's configuration.environment
nsNoNamespace to create the resources in, default is "default"
imagePullSecretNoName of the Kubernetes image pull secret, if omitted the deployment spec is not provided an image pull secret
portNoPort the container service listens on, if omitted the deployment spec will have no configured liveness or readiness probe and no service will be created
pathNoAbsolute path under the hostname the ingress controller should use for this service, if omitted no ingress rule is created
hostNoHost name to use in ingress rule, only has effect if path is provided, if omitted when path is provided, the rule is created under the wildcard host
protocolNoScheme to use when setting the URL for the service endpoint, "https" or "http", default is "http"
deploymentSpecNoStringified JSON Kubernetes deployment spec to overlay on top of default deployment spec, it only needs to contain the properties you want to add or override from the default
serviceSpecNoStringified JSON Kubernetes service spec to overlay on top of default service spec, it only needs to contain the properties you want to add or override from the default

Support

General support questions should be discussed in the #support channel in our community Slack team at atomist-community.slack.com.

If you find a problem, please create an issue.

Development

Before developing this project, you will need to install Node.js and configure your environment.

Node.js

You will need to have Node.js installed. To verify that the right versions are installed, please run:

$ node -v
v9.7.1
$ npm -v
5.6.0

The node version should be 8 or greater and the npm version should be 5 or greater.

Cloning the repository and installing dependencies

To get started run the following commands to clone the project, install its dependencies, and build the project:

$ git clone git@github.com:atomist/k8-automation.git
$ cd k8-automation
$ npm install
$ npm run build

Configuring your environment

If this is the first time you will be running an Atomist API client locally, you should first configure your system using the atomist script:

$ `npm bin`/atomist config

The script does two things: records what Slack team you want your automations running in and creates a GitHub personal access token with "repo" and "read:org" scopes.

The script will prompt you for your Atomist workspace/team ID, or you can supply it using the --team TEAM_ID command-line option. You can get your Atomist team ID from the settings page for your Atomist workspace or by typing team in a DM to the Atomist bot.

The script will prompt you for your GitHub credentials. It needs them to create the GitHub personal access token. Atomist does not store your credentials and only writes the generated token to your local machine.

The Atomist API client authenticates using a GitHub personal access token. The Atomist API uses the token to confirm you are who you say you are and are in a GitHub organization connected to the Slack team in which you are running the automations. In addition, it uses the token when performing any operations that access the GitHub API.

Running locally

You can run this automation client locally, allowing you to change the source code of this project and immediately see the effects in your environment with the following command

$ npm run autostart

To run in a more traditional manner, build the project and then simple start it.

$ npm run build
$ npm start

To download and run the Docker image of this project, run the following command

$ docker run --rm -e GITHUB_TOKEN=YOUR_TOKEN -e ATOMIST_TEAMS=TEAM_ID \
    atomist/k8-automation:VERSION

replacing YOUR_TOKEN and TEAM_ID with the token and team ID from your ~/.atomist/client.config.json created by the atomist config command and VERSION with the latest release of this repo. Note that this will not be running any code from your local machine but the code in the Docker image.

Build and Test

CommandReason
npm installinstall all the required packages
npm run buildlint, compile, and test
npm startstart the Atomist automation client
npm run autostartrun the client, refreshing when files change
npm run lintrun tslint against the TypeScript
npm run compilecompile all TypeScript into JavaScript
npm testrun tests and ensure everything is working
npm run autotestrun tests continuously
npm run cleanremove stray compiled JavaScript files and build directory

Release

Releases are managed by the Atomist SDM. Press the "Release" button in the Atomist dashboard or Slack.


Created by Atomist. Need Help? Join our Slack team.

0.9.0

6 years ago

0.8.0

6 years ago

0.7.3

6 years ago

0.7.2

6 years ago

0.7.1

6 years ago

0.7.0

6 years ago

0.6.3

6 years ago

0.6.2

6 years ago

0.6.1

6 years ago

0.6.0

6 years ago

0.5.3

6 years ago

0.5.2

6 years ago

0.5.1

6 years ago

0.5.0

6 years ago

0.4.0

6 years ago

0.3.0

6 years ago

0.2.6

6 years ago

0.2.5

6 years ago

0.2.4

6 years ago

0.2.3

6 years ago

0.2.2

6 years ago

0.2.1

6 years ago

0.2.0

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago