GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — bake: handle git auth token when parsing remote definition by crazy-max · Pull Request #288 · docker/actions-toolkit

bake: handle git auth token when parsing remote definition #288

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.

Sign up for GitHub

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

Merged
crazy-max merged 1 commit into docker:main from crazy-max:bake-auth-token
Apr 12, 2024

Uh oh!

There was an error while loading. Please reload this page.

Merged

bake: handle git auth token when parsing remote definition #288

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
1 commit
Select commit
329c1c7
bake: handle git auth token when parsing remote definition
crazy-max Apr 12, 2024
File filter
Filter by extension


Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view

There are no files selected for viewing

8 changes: 8 additions & 0 deletions 8 .github/workflows/test.yml
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ on:

env:
NODE_VERSION: "20"
BUILDX_VERSION: "v0.14.0-rc1"

jobs:
test:
Expand Down Expand Up @@ -102,6 +103,13 @@ jobs:
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'yarn'
-
name: Set up Docker Buildx
if: startsWith(matrix.os, 'ubuntu')
uses: docker/setup-buildx-action@v3
with:
version: ${{ env.BUILDX_VERSION }}
driver: docker
-
name: Install
run: yarn install
Expand Down
20 changes: 17 additions & 3 deletions 20 __tests__/buildx/bake.test.itg.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,28 @@ maybe('getDefinition', () => {
[
'https://github.com/docker/buildx.git#v0.10.4',
['binaries-cross'],
path.join(fixturesDir, 'bake-buildx-0.10.4-binaries-cross.json')
path.join(fixturesDir, 'bake-buildx-0.10.4-binaries-cross.json'),
false,
],
])('given %p', async (source: string, targets: string[], out: string) => {
// TODO: uncomment this test case when we have access to the private repo using an access token
// [
// 'https://github.com/docker/test-docker-action.git#remote-private',
// ['default'],
// path.join(fixturesDir, 'bake-test-docker-action-remote-private.json'),
// true,
// ]
])('given %p', async (source: string, targets: string[], out: string, auth) => {
const gitAuthToken = process.env.GITHUB_TOKEN || '';
if (auth && !gitAuthToken) {
console.log(`Git auth token not available, skipping test`);
return;
}
const bake = new Bake();
const expectedDef = <BakeDefinition>JSON.parse(fs.readFileSync(out, {encoding: 'utf-8'}).trim())
expect(await bake.getDefinition({
source: source,
targets: targets
targets: targets,
githubToken: gitAuthToken,
})).toEqual(expectedDef);
});
});
11 changes: 11 additions & 0 deletions 11 __tests__/fixtures/bake-test-docker-action-remote-private.json
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"target": {
"default": {
"context": "https://github.com/docker/test-docker-action.git#remote-private",
"dockerfile": "Dockerfile",
"tags": [
"foo"
]
}
}
}
2 changes: 1 addition & 1 deletion 2 dev.Dockerfile
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

ARG NODE_VERSION=20
ARG DOCKER_VERSION=26.0.0
ARG BUILDX_VERSION=0.13.1
ARG BUILDX_VERSION=0.14.0-rc1

FROM node:${NODE_VERSION}-alpine AS base
RUN apk add --no-cache cpio findutils git
Expand Down
9 changes: 9 additions & 0 deletions 9 src/buildx/bake.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ export interface BakeCmdOpts {
sbom?: string;
source?: string;
targets?: Array<string>;

githubToken?: string; // for auth with remote definitions on private repos
}

export class Bake {
Expand All @@ -48,6 +50,13 @@ export class Bake {
public async getDefinition(cmdOpts: BakeCmdOpts, execOptions?: ExecOptions): Promise<BakeDefinition> {
execOptions = execOptions || {ignoreReturnCode: true};
execOptions.ignoreReturnCode = true;
if (cmdOpts.githubToken) {
execOptions.env = Object.assign({}, process.env, {
BUILDX_BAKE_GIT_AUTH_TOKEN: cmdOpts.githubToken
}) as {
[key: string]: string;
};
}

const args = ['bake'];

Expand Down
13 changes: 6 additions & 7 deletions 13 src/buildx/inputs.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -77,24 +77,23 @@ export class Inputs {
}

public static resolveBuildSecretString(kvp: string): string {
return Inputs.resolveBuildSecret(kvp, false);
const [key, file] = Inputs.resolveBuildSecret(kvp, false);
return `id=${key},src=${file}`;
}

public static resolveBuildSecretFile(kvp: string): string {
return Inputs.resolveBuildSecret(kvp, true);
const [key, file] = Inputs.resolveBuildSecret(kvp, true);
return `id=${key},src=${file}`;
}

public static resolveBuildSecretEnv(kvp: string): string {
const [key, value] = parseKvp(kvp);

return `id=${key},env=${value}`;
}

public static resolveBuildSecret(kvp: string, file: boolean): string {
public static resolveBuildSecret(kvp: string, file: boolean): [string, string] {
const [key, _value] = parseKvp(kvp);

let value = _value;

if (file) {
if (!fs.existsSync(value)) {
throw new Error(`secret file ${value} not found`);
Expand All @@ -103,7 +102,7 @@ export class Inputs {
}
const secretFile = Context.tmpName({tmpdir: Context.tmpDir()});
fs.writeFileSync(secretFile, value);
return `id=${key},src=${secretFile}`;
return [key, secretFile];
}

public static getProvenanceInput(name: string): string {
Expand Down
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.