Sign inSign up

lizheming/drone-js

By lizheming

Updated over 7 years ago

Drone extensions to support javascript configuration files

Image
0

346

lizheming/drone-js repository overview

drone-js-config

Docker Pulls

Drone extensions to support javascript configuration files, just like the following content. We support both github, gitlab, bitbucket, gogs and gitea.

//.drone.js
module.exports = [
  Pipeline("node6", "node:6"),
  Pipeline("node8", "node:8")
];

function Pipeline(name, image) {
  return {
    kind: "pipeline",
    name,

    steps: [
      {
        name: "test",
        image,
        commands: [
          "npm install",
          "npm test"
        ]
      }
    ]
  };
}

HOW TO USE

  1. Generate a shared secret key. This key is used to secure communication between the server and agents. The secret should be 32 bytes.

    $ openssl rand -hex 16
    558f3eacbfd5928157cbfe34823ab921
    
  2. Generate a GitHub/Gitlab/Bitbucket/Gogs/Gitea access token. This token is used to fetch the jsonnet configuration file from the repository. This token must therefore have sufficient permission to do so. Here is an example where to generate access token:

  3. Install the plugin by pulling and running the container.

    docker run \
      -p 3000:3000 \
      -e PLUGIN_SECRET=558f3eacbfd5928157cbfe34823ab921 \
      -e GITHUB_TOKEN=GITHUB8168c98304b \
      lizheming/drone-js
    
  4. Once the extension is installed and running, you need to modify your Drone server configuration and provide the extension endpoint and shared secret.

    -e DRONE_YAML_ENDPOINT=http://...
    -e DRONE_YAML_SECRET=558f3eacbfd5928157cbfe34823ab921
    
  5. Rename Configuration end with .js such as .drone.js.

  6. At last, you just add .drone.js file to your repo. It should exports an array drone config object.

    module.exports = [
      Pipeline("node6", "node:6"),
      Pipeline("node8", "node:8")
    ];
    
    function Pipeline(name, image) {
      return {
        kind: "pipeline",
        name,
    
        steps: [
          {
            name: "test",
            image,
            commands: [
              "npm install",
              "npm test"
            ]
          }
        ]
      };
    }
    

Settings

We take support for all VCS which drone supports, not only GitHub but also GitLab, Bitbucket, Gogs and Gitea. Let we have a look how config in different VCS.

Github

You should pass GITHUB_TOKEN to container, if you're using GitHub Enterprise, you should pass GITHUB_SERVER to custom server url.

docker run \
  -p 3000:3000 \
  -e PLUGIN_SECRET=558f3eacbfd5928157cbfe34823ab921 \
  -e GITHUB_SERVER=https://api.github.com
  -e GITHUB_TOKEN=GITHUB8168c98304b \
  lizheming/drone-js
Gitlab

You should pass GITLAB_TOKEN to container, if you're self hosting GitLab, you should also pass GITLAB_SERVER to custom server url.

docker run \
  -p 3000:3000 \
  -e PLUGIN_SECRET=558f3eacbfd5928157cbfe34823ab921 \
  -e GITLAB_SERVER=https://gitlab.com/api/v4
  -e GITLAB_TOKEN=GITLAB8168c98304b \
  lizheming/drone-js
Bitbucket

You should pass BITBUCKET_USERNAME and BITBUCKET_APP_PASSWORD to container, if you're using Bitbucket Server, you should also pass BITBUCKET_SERVER to set server url.

docker run \
  -p 3000:3000 \
  -e PLUGIN_SECRET=558f3eacbfd5928157cbfe34823ab921 \
  -e BITBUCKET_SERVER=https://api.bitbucket.org/2.0
  -e BITBUCKET_USERNAME=lizheming \
  -e BITBUCKET_APP_PASSWORD=BITBUCKET8168c98304b \
  lizheming/drone-js

BTW, if your bitbucket server support personal access token, you can pass it without bitbucket username.

docker run \
  -p 3000:3000 \
  -e PLUGIN_SECRET=558f3eacbfd5928157cbfe34823ab921 \
  -e BITBUCKET_SERVER=https://api.bitbucket.org/2.0
  -e BITBUCKET_TOKEN=BITBUCKET8168c98304b \
  lizheming/drone-js

You can also just pass BITBUCKET_USERNAME and BITBUCKET_PASSWORD, but it'll fail if your account open two step authencation.

docker run \
  -p 3000:3000 \
  -e PLUGIN_SECRET=558f3eacbfd5928157cbfe34823ab921 \
  -e BITBUCKET_SERVER=https://api.bitbucket.org/2.0
  -e BITBUCKET_USERNAME=lizheming \
  -e BITBUCKET_PASSWORD=xxxx \
  lizheming/drone-js
Gogs/Gitea

You should pass GOGS_TOKEN or GITEA_TOKEN to container, if you're self hosting Gogs/Gitea, you should also pass GOGS_SERVER or GITEA_SERVER to custom server url.

docker run \
  -p 3000:3000 \
  -e PLUGIN_SECRET=558f3eacbfd5928157cbfe34823ab921 \
  -e GOGS_SERVER=https://try.gogs.io/api/v1 \
  -e GOGS_TOKEN=GOGS8168c98304b \
  lizheming/drone-js

Configuration

PLUGIN_SECRET

The server and extension authenticate http requests using a shared secret. You must provide the shared secret to both the extenion and the server.

docker run \
  -p 3000:3000 \
  -e PLUGIN_SECRET=558f3eacbfd5928157cbfe34823ab921 \
  -e GITHUB_TOKEN=GITHUB8168c98304b \
  lizheming/drone-js

And it should be same with DRONE_YAML_SECRET.

Environment

  • PLUGIN_ADDRESS
  • PLUGIN_SECRET
  • GITHUB_SERVER
  • GITHUB_TOKEN
  • GITLAB_SERVER
  • GITLAB_TOKEN
  • BITBUCKET_SERVER
  • BITBUCKET_USERNAME
  • BITBUCKET_PASSWORD
  • BITBUCKET_APP_PASSWORD
  • GOGS_SERVER
  • GOGS_TOKEN
  • GITEA_SERVER
  • GITEA_TOKEN

Tag summary

Content type

Image

Digest

Size

39.3 MB

Last updated

over 7 years ago

docker pull lizheming/drone-js