-
Notifications
You must be signed in to change notification settings - Fork 343
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bitbucket runner support #798
Conversation
DavidGOrtega
commented
Nov 1, 2021
- closes Support for Bitbucket Cloud Pipelines self-hosted runners #646
- Refactors runner a bit
This is an ideal solution (that unfortunately does not work) without having to use docker, just the Java agent. async startRunner(opts) {
const { projectPath } = this;
const { workdir, name, labels: labelsstr } = opts;
const labels = labelsstr.split(',')
const os = process.platform === 'darwin' ? 'macos' : 'linux';
labels.push(os);
try {
const { uuid: accountId } = await this.request({ endpoint: `/user` });
const { uuid: repoId } = await this.request({
endpoint: `/repositories/${projectPath}`
});
const {
uuid,
oauth_client: { id, secret }
} = await this.registerRunner({ name, labels });
const destination = resolve(workdir, 'bb-runner.tar.gz');
const ver = '1.322';
const url = `https://product-downloads.atlassian.com/software/bitbucket/pipelines/atlassian-bitbucket-pipelines-runner-${ver}.tar.gz`;
await download({ url, path: destination });
await tar.extract({ file: destination, cwd: workdir });
await exec(`chmod -R 777 ${workdir}`);
if (os==='linux') {
await exec(`
sudo tee /usr/bin/retry << 'EOF'
#!/bin/bash
exec env GIT_LFS_SKIP_SMUDGE=1 "$\{@:2}"
EOF'
`);
await exec(`chmod 777 /usr/bin/retry`);
}
const command = `java -jar \
-Dbitbucket.pipelines.runner.account.uuid=${accountId} \
-Dbitbucket.pipelines.runner.repository.uuid=${repoId} \
-Dbitbucket.pipelines.runner.uuid=${uuid} \
-Dbitbucket.pipelines.runner.oauth.client.id=${id} \
-Dbitbucket.pipelines.runner.oauth.client.secret=${secret} \
-Dbitbucket.pipelines.runner.directory.working=${workdir}/temp \
-Dbitbucket.pipelines.runner.runtime=${os}-bash \
-Dbitbucket.pipelines.runner.docker.uri=unix:///var/run/docker.sock \
-Dbitbucket.pipelines.runner.scheduled.state.update.initial.delay.seconds=0 \
-Dbitbucket.pipelines.runner.scheduled.state.update.period.seconds=30 \
-Dbitbucket.pipelines.runner.environment=PRODUCTION \
-Dfile.encoding=UTF-8 \
-Dsun.jnu.encoding=UTF-8 \
${workdir}/bin/runner.jar`
return spawn(command, { shell: true });
} catch (err) {
throw new Error(`Failed preparing runner: ${err.message}`);
}
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this ready for review?
- it's ok if Docker and/or GPUs aren't fully supported yet
- need a corresponding PR on https://cml.dev/doc/self-hosted-runners#allocating-cloud-compute-resources-with-cml (adding a Bitbucket tab with a workflow)
- no need to do the whole 4-example-repo-cases thing (yet)
😮 single was supported for everyone as far as I remembered! I mean, not depending on the capability. GH originally did not support it on its own and we had a mechanism in place... Did we remove it? |
@0x2b3bfa0 now we are honouring single. We can indeed use this method for anyone instead of relying in native single. |
Note that, unlike on GitHub and GitLab, Bitbucket will fail immediately if there isn't any self-hosted runner able to satisfy the specified |
Note that runner-side |
Generating Application PasswordsUse https://bitbucket.org/account/settings/app-passwords/new to generate a new application password.
|
The following pipelines:
custom:
test:
- step:
image: node
script:
- curl https://releases.hashicorp.com/terraform/1.2.1/terraform_1.2.1_linux_amd64.zip | funzip > /bin/terraform && chmod 755 /bin/terraform
- npx github:iterative/cml#bb-runner runner --cml-version=github:iterative/cml#bb-runner --cloud=aws --cloud-region=us-west-1 --cloud-type=g2.2xlarge --labels=example
- step:
runs-on: [self.hosted, example]
image: alpine
script:
- echo hello world
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It works!™ Created #1015 collecting potential enhancements and iterative/cml.dev#243 for documentation.
@DavidGOrtega, any last will before merging? |
I do not see what its your point. GH also failed in the past if we had no runner to execute a job. Is there anything we can do about it? Indeed the wait mechanism that we have in terraform covered to needs:
No if... we remove the 10 seconds wait. Indeed we could control that issue in every runner forcing the kill of the process since we are the ones that cleanups the resources. Being polite we are having issues like #990 |
My point is that iterative/terraform-provider-iterative#315 is still invalid, and we still need the readiness check for some of the reasons you mention plus this one. |
Great! While it could still (theoretically) take a second job in the time it takes us to parse the completion logs, that's unlikely to happen in practice. May work. 🤷🏼♂️ |