Merge pull request #3 from flant/build_publish_and_run_actions

Implement build, publish and run actions
This commit is contained in:
Alexey Igrychev
2020-05-28 11:47:13 +01:00
committed by GitHub
16 changed files with 133751 additions and 5 deletions

View File

@@ -3,12 +3,15 @@
</p>
___
This action set allows you to organize CI/CD with GitHub Actions and [werf](https://github.com/flant/werf). The set consists of four independent complex actions:
This action set allows you to organize CI/CD with GitHub Actions and [werf](https://github.com/flant/werf). The set consists of several independent and complex actions:
- [flant/werf-actions/converge](https://github.com/flant/werf-actions/tree/master/converge)
- [flant/werf-actions/build-and-publish](https://github.com/flant/werf-actions/tree/master/build-and-publish)
- [flant/werf-actions/build](https://github.com/flant/werf-actions/tree/master/build)
- [flant/werf-actions/publish](https://github.com/flant/werf-actions/tree/master/build)
- [flant/werf-actions/deploy](https://github.com/flant/werf-actions/tree/master/deploy)
- [flant/werf-actions/dismiss](https://github.com/flant/werf-actions/tree/master/dismiss)
- [flant/werf-actions/run](https://github.com/flant/werf-actions/tree/master/run)
- [flant/werf-actions/cleanup](https://github.com/flant/werf-actions/tree/master/cleanup)
Each action combines all the necessary steps in itself and logic may be divided into __environment setup__ and launching the corresponding command.
@@ -149,6 +152,29 @@ dismiss:
env: production
```
### run
```yaml
run:
name: Run
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Run
uses: flant/werf-actions/run@master
with:
image: backend
args: rails server
kube-config-base64-data: ${{ secrets.KUBE_CONFIG_BASE64_DATA }}
env:
WERF_DOCKER_OPTIONS: "-d -p 3000:3000"
```
### cleanup
```yaml

106
build/README.md Normal file
View File

@@ -0,0 +1,106 @@
<p align="center">
<img src="https://github.com/flant/werf/raw/master/docs/images/werf-logo.svg?sanitize=true" style="max-height:100%;" height="175">
</p>
___
The action combines all the necessary steps in itself and logic may be divided into environment setup and launching `werf build`.
## Action in Details
### werf binary setup
By default, all actions setup actual werf version for [1.1 stable channel](https://werf.io/releases.html) (more details about channels, werf release cycle and compatibility promise [here](https://github.com/flant/werf#backward-compatibility-promise)).
Using `group` and `channel` inputs the user can switch the release channel.
> This is recommended approach to be up-to-date and to use actual werf version without changing configurations
```yaml
- uses: flant/werf-actions/build@master
with:
group: 1.1
channel: alpha
```
Withal, it is not necessary to work within release channels, and the user might specify certain werf version with `version` input.
```yaml
- uses: flant/werf-actions/build@master
with:
version: v1.1.16
```
### kubeconfig setup (*optional*)
The _kubeconfig_ may be used for deployment, cleanup, distributed locks and caches. Thus, the configuration should be added before step with the action or passed as base64 encoded data with `kube-config-base64-data` input:
* Prepare _kubeconfig_ (e.g. `cat ~/.kube/config | base64`) and save in GitHub Project Secrets (e.g. with name `KUBE_CONFIG_BASE64_DATA`).
* Pass secret with `kube-config-base64-data` input:
```yaml
- uses: flant/werf-actions/build@master
with:
kube-config-base64-data: ${{ secrets.KUBE_CONFIG_BASE64_DATA }}
```
### werf ci-env
This command performs _docker login_ using `github-token`, sets up predefined variables based on GitHub Workflow context.
**Note** that `github-token` is optional in this action, and the input is there in case you need to use a non-default token.
By default, action will use the token provided to your workflow.
## Working with werf options
Any werf option can be defined with environment variables:
```yaml
- uses: flant/werf-actions/build@master
env:
WERF_LOG_VERBOSE: "on"
WERF_TAG_CUSTOM_TAG1: tag1
WERF_TAG_CUSTOM_TAG2: tag2
```
## Inputs
```yaml
group:
description: 'The MAJOR.MINOR version'
default: '1.1'
required: false
channel:
description: 'The one of the following channel: alpha, beta, ea, stable, rock-solid'
default: 'stable'
required: false
version:
description: 'The certain version'
required: false
github-token:
description: 'The GitHub token used to login and to interact with Docker Github Packages'
default: ${{ github.token }}
required: false
kube-config-base64-data:
description: 'Base64 encoded kubeconfig data used for deployment, cleanup and distributed locks'
required: false
```
## Example
```yaml
build:
name: Build
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Build
uses: flant/werf-actions/build@master
with:
kube-config-base64-data: ${{ secrets.KUBE_CONFIG_BASE64_DATA }}
```

28
build/action.yml Normal file
View File

@@ -0,0 +1,28 @@
name: werf build
author: 'Flant'
description: 'Prepare the environment and perform image building with werf'
branding:
color: blue
icon: anchor
inputs:
group:
description: 'The MAJOR.MINOR version'
default: '1.1'
required: false
channel:
description: 'The one of the following channel: alpha, beta, ea, stable, rock-solid'
default: 'stable'
required: false
version:
description: 'The certain version'
required: false
github-token:
description: 'The GitHub token used to login and to interact with Docker Github Packages'
default: ${{ github.token }}
required: false
kube-config-base64-data:
description: 'Base64 encoded kubeconfig data used for deployment, cleanup and distributed locks'
required: false
runs:
using: 'node12'
main: 'index.js'

44385
build/index.js Normal file

File diff suppressed because one or more lines are too long

View File

@@ -1,3 +1,3 @@
#!/bin/bash -e
for pkg in build-and-publish cleanup converge deploy dismiss install; do ncc build src/$pkg.ts -o $pkg; done
for pkg in build build-and-publish cleanup converge deploy dismiss install publish run; do ncc build src/$pkg.ts -o $pkg; done

5
package-lock.json generated
View File

@@ -2716,6 +2716,11 @@
"integrity": "sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw=",
"dev": true
},
"string-argv": {
"version": "0.3.1",
"resolved": "https://registry.npmjs.org/string-argv/-/string-argv-0.3.1.tgz",
"integrity": "sha512-a1uQGz7IyVy9YwhqjZIZu1c8JO8dNIe20xBmSS6qu9kv++k3JGzCVmprbNN5Kn+BgzD5E7YYwg1CcjuJMRNsvg=="
},
"string-natural-compare": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/string-natural-compare/-/string-natural-compare-3.0.1.tgz",

View File

@@ -10,10 +10,11 @@
"dotenv": "^8.2.0",
"ncc": "^0.3.6",
"semver": "^7.3.2",
"string-argv": "^0.3.1",
"superagent": "^3.8.3",
"tmp": "^0.2.1",
"ws": ">=3.3.1",
"typescript-string-operations": "^1.3.2"
"typescript-string-operations": "^1.3.2",
"ws": ">=3.3.1"
},
"devDependencies": {
"@types/node": "^12.7.12",
@@ -32,7 +33,7 @@
"format": "prettier --write **/*.ts",
"format-check": "prettier --check **/*.ts",
"lint": "eslint src/**/*.ts",
"pack": "./pack.sh",
"pack": "pack.sh",
"all": "npm run build && npm run format && npm run lint && npm run pack"
},
"private": true,

106
publish/README.md Normal file
View File

@@ -0,0 +1,106 @@
<p align="center">
<img src="https://github.com/flant/werf/raw/master/docs/images/werf-logo.svg?sanitize=true" style="max-height:100%;" height="175">
</p>
___
The action combines all the necessary steps in itself and logic may be divided into environment setup and launching `werf publish`.
## Action in Details
### werf binary setup
By default, all actions setup actual werf version for [1.1 stable channel](https://werf.io/releases.html) (more details about channels, werf release cycle and compatibility promise [here](https://github.com/flant/werf#backward-compatibility-promise)).
Using `group` and `channel` inputs the user can switch the release channel.
> This is recommended approach to be up-to-date and to use actual werf version without changing configurations
```yaml
- uses: flant/werf-actions/publish@master
with:
group: 1.1
channel: alpha
```
Withal, it is not necessary to work within release channels, and the user might specify certain werf version with `version` input.
```yaml
- uses: flant/werf-actions/publish@master
with:
version: v1.1.16
```
### kubeconfig setup (*optional*)
The _kubeconfig_ may be used for deployment, cleanup, distributed locks and caches. Thus, the configuration should be added before step with the action or passed as base64 encoded data with `kube-config-base64-data` input:
* Prepare _kubeconfig_ (e.g. `cat ~/.kube/config | base64`) and save in GitHub Project Secrets (e.g. with name `KUBE_CONFIG_BASE64_DATA`).
* Pass secret with `kube-config-base64-data` input:
```yaml
- uses: flant/werf-actions/publish@master
with:
kube-config-base64-data: ${{ secrets.KUBE_CONFIG_BASE64_DATA }}
```
### werf ci-env
This command performs _docker login_ using `github-token`, sets up predefined variables based on GitHub Workflow context.
**Note** that `github-token` is optional in this action, and the input is there in case you need to use a non-default token.
By default, action will use the token provided to your workflow.
## Working with werf options
Any werf option can be defined with environment variables:
```yaml
- uses: flant/werf-actions/publish@master
env:
WERF_LOG_VERBOSE: "on"
WERF_TAG_CUSTOM_TAG1: tag1
WERF_TAG_CUSTOM_TAG2: tag2
```
## Inputs
```yaml
group:
description: 'The MAJOR.MINOR version'
default: '1.1'
required: false
channel:
description: 'The one of the following channel: alpha, beta, ea, stable, rock-solid'
default: 'stable'
required: false
version:
description: 'The certain version'
required: false
github-token:
description: 'The GitHub token used to login and to interact with Docker Github Packages'
default: ${{ github.token }}
required: false
kube-config-base64-data:
description: 'Base64 encoded kubeconfig data used for deployment, cleanup and distributed locks'
required: false
```
## Example
```yaml
publish:
name: Publish
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Publish
uses: flant/werf-actions/publish@master
with:
kube-config-base64-data: ${{ secrets.KUBE_CONFIG_BASE64_DATA }}
```

28
publish/action.yml Normal file
View File

@@ -0,0 +1,28 @@
name: werf publish
author: 'Flant'
description: 'Prepare the environment and perform image publishing with werf'
branding:
color: blue
icon: anchor
inputs:
group:
description: 'The MAJOR.MINOR version'
default: '1.1'
required: false
channel:
description: 'The one of the following channel: alpha, beta, ea, stable, rock-solid'
default: 'stable'
required: false
version:
description: 'The certain version'
required: false
github-token:
description: 'The GitHub token used to login and to interact with Docker Github Packages'
default: ${{ github.token }}
required: false
kube-config-base64-data:
description: 'Base64 encoded kubeconfig data used for deployment, cleanup and distributed locks'
required: false
runs:
using: 'node12'
main: 'index.js'

44385
publish/index.js Normal file

File diff suppressed because one or more lines are too long

117
run/README.md Normal file
View File

@@ -0,0 +1,117 @@
<p align="center">
<img src="https://github.com/flant/werf/raw/master/docs/images/werf-logo.svg?sanitize=true" style="max-height:100%;" height="175">
</p>
___
The action combines all the necessary steps in itself and logic may be divided into environment setup and launching `werf run`.
## Action in Details
### werf binary setup
By default, all actions setup actual werf version for [1.1 stable channel](https://werf.io/releases.html) (more details about channels, werf release cycle and compatibility promise [here](https://github.com/flant/werf#backward-compatibility-promise)).
Using `group` and `channel` inputs the user can switch the release channel.
> This is recommended approach to be up-to-date and to use actual werf version without changing configurations
```yaml
- uses: flant/werf-actions/run@master
with:
group: 1.1
channel: alpha
```
Withal, it is not necessary to work within release channels, and the user might specify certain werf version with `version` input.
```yaml
- uses: flant/werf-actions/run@master
with:
version: v1.1.16
```
### kubeconfig setup (*optional*)
The _kubeconfig_ may be used for deployment, cleanup, distributed locks and caches. Thus, the configuration should be added before step with the action or passed as base64 encoded data with `kube-config-base64-data` input:
* Prepare _kubeconfig_ (e.g. `cat ~/.kube/config | base64`) and save in GitHub Project Secrets (e.g. with name `KUBE_CONFIG_BASE64_DATA`).
* Pass secret with `kube-config-base64-data` input:
```yaml
- uses: flant/werf-actions/run@master
with:
kube-config-base64-data: ${{ secrets.KUBE_CONFIG_BASE64_DATA }}
```
### werf ci-env
This command performs _docker login_ using `github-token`, sets up predefined variables based on GitHub Workflow context.
**Note** that `github-token` is optional in this action, and the input is there in case you need to use a non-default token.
By default, action will use the token provided to your workflow.
## Working with werf options
Any werf option can be defined with environment variables:
```yaml
- uses: flant/werf-actions/run@master
env:
WERF_LOG_VERBOSE: "on"
WERF_TAG_CUSTOM_TAG1: tag1
WERF_TAG_CUSTOM_TAG2: tag2
```
## Inputs
```yaml
inputs:
group:
description: 'The MAJOR.MINOR version'
default: '1.1'
required: false
channel:
description: 'The one of the following channel: alpha, beta, ea, stable, rock-solid'
default: 'stable'
required: false
version:
description: 'The certain version'
required: false
image:
description: 'The image name from werf.yaml (werf run [options] [IMAGE_NAME] [-- COMMAND ARG...])'
required: false
args:
description: 'The specific command with arguments (werf run [options] [IMAGE_NAME] [-- COMMAND ARG...])'
required: false
github-token:
description: 'The GitHub token used to login and to interact with Docker Github Packages'
default: ${{ github.token }}
required: false
kube-config-base64-data:
description: 'Base64 encoded kubeconfig data used for deployment, cleanup and distributed locks'
required: false
```
## Example
```yaml
run:
name: Run
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Run
uses: flant/werf-actions/run@master
with:
image: backend
args: rails server
kube-config-base64-data: ${{ secrets.KUBE_CONFIG_BASE64_DATA }}
env:
WERF_DOCKER_OPTIONS: "-d -p 3000:3000"
```

34
run/action.yml Normal file
View File

@@ -0,0 +1,34 @@
name: werf run
author: 'Flant'
description: 'Prepare the environment and run built image with werf'
branding:
color: blue
icon: anchor
inputs:
group:
description: 'The MAJOR.MINOR version'
default: '1.1'
required: false
channel:
description: 'The one of the following channel: alpha, beta, ea, stable, rock-solid'
default: 'stable'
required: false
version:
description: 'The certain version'
required: false
image:
description: 'The image name from werf.yaml (werf run [options] [IMAGE_NAME] [-- COMMAND ARG...])'
required: false
args:
description: 'The specific command with arguments (werf run [options] [IMAGE_NAME] [-- COMMAND ARG...])'
required: false
github-token:
description: 'The GitHub token used to login and to interact with Docker Github Packages'
default: ${{ github.token }}
required: false
kube-config-base64-data:
description: 'Base64 encoded kubeconfig data used for deployment, cleanup and distributed locks'
required: false
runs:
using: 'node12'
main: 'index.js'

44458
run/index.js Normal file

File diff suppressed because one or more lines are too long

12
src/build.ts Normal file
View File

@@ -0,0 +1,12 @@
import * as core from '@actions/core'
import {PrepareEnvironAndRunWerfCommand} from './common'
async function run(): Promise<void> {
try {
await PrepareEnvironAndRunWerfCommand(['build'])
} catch (error) {
core.setFailed(error.message)
}
}
run()

12
src/publish.ts Normal file
View File

@@ -0,0 +1,12 @@
import * as core from '@actions/core'
import {PrepareEnvironAndRunWerfCommand} from './common'
async function run(): Promise<void> {
try {
await PrepareEnvironAndRunWerfCommand(['publish'])
} catch (error) {
core.setFailed(error.message)
}
}
run()

43
src/run.ts Normal file
View File

@@ -0,0 +1,43 @@
import * as core from '@actions/core'
import {PrepareEnvironAndRunWerfCommand} from './common'
import {String} from 'typescript-string-operations'
import { parseArgsStringToArgv } from 'string-argv'
async function run(): Promise<void> {
try {
let args = []
args.push('run')
const werfImageName = core.getInput('image')
if (werfImageName !== '') {
args.push(werfImageName)
}
// legacy
if (process.env.WERF_DOCKER_OPTIONS) {
args.push(
String.Format("--docker-options={0}", process.env.WERF_DOCKER_OPTIONS)
)
}
// legacy
if (process.env.WERF_DRY_RUN) {
args.push('--dry-run')
}
// legacy
const commandAndArgs = core.getInput('args')
if (commandAndArgs !== '') {
const parsedCommandAndArgs = parseArgsStringToArgv(commandAndArgs)
args.push('--')
args = args.concat(parsedCommandAndArgs)
}
await PrepareEnvironAndRunWerfCommand(args)
} catch (error) {
core.setFailed(error.message)
}
}
run()