Skip to content
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

Add multi_dockerignore option #249

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ Inputs are provided using the `with:` section of your workflow YML file.
| layer_cache | Use cached layers of previously built images for this project | false | true |
| registry_secrets | JSON string containing image registry credentials used to pull base images | false | |
| default_branch | Used to finalize a release when code is pushed to this branch | false | Repo configured [default branch](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/about-branches#about-the-default-branch) |
| multi_dockerignore | Respect .dockerignore in each service | false | false |

`balena_token` and other tokens needs to be stored in GitHub as an [encrypted secret](https://docs.github.com/en/actions/security-guides/encrypted-secrets#creating-encrypted-secrets-for-a-repository) that GitHub Actions can access.

Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ inputs:
description: Branch for finalizing releases
required: false
default: ""
multi_dockerignore:
description: Use service's dockerignore file
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@karaxuna after enabling external contributors, I now see a different error in CI
See: https://github.com/balena-io/deploy-to-balena-action/actions/runs/4505762867/jobs/7932156158#step:4:95

Can you try removing this ' and see whether that fixes the yml?

required: false
default: false
outputs:
release_id:
description: ID of the release built
Expand Down
1 change: 1 addition & 0 deletions src/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ export async function run(
releaseId = await balena.push(inputs.fleet, inputs.source, inputs.cache, {
...buildOptions,
noCache: inputs.layerCache === false,
multiDockerignore: inputs.multiDockerignore,
});
} catch (e: any) {
core.error(e.message);
Expand Down
6 changes: 6 additions & 0 deletions src/balena-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ type BuildOptions = {
noCache: boolean;
draft: boolean;
tags: Tags;
multiDockerignore: boolean;
};

const DEFAULT_BUILD_OPTIONS: Partial<BuildOptions> = {
draft: true,
noCache: false,
multiDockerignore: false,
};

let sdk: ReturnType<typeof balena.getSdk> | null = null;
Expand Down Expand Up @@ -99,6 +101,10 @@ export async function push(
pushOpt.push('--nocache');
}

if (buildOpt.multiDockerignore) {
pushOpt.push('--multi-dockerignore');
}

let releaseId: string | null = null;

return new Promise((resolve, reject) => {
Expand Down
1 change: 1 addition & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const inputs: Inputs = {
githubToken: core.getInput('github_token', { required: false }),
layerCache: core.getBooleanInput('layer_cache', { required: false }),
defaultBranch: core.getInput('default_branch', { required: false }),
multiDockerignore: core.getBooleanInput('multi_dockerignore', { required: false }),
};

(async () => {
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export type Inputs = {
createTag: boolean;
layerCache: boolean;
defaultBranch: string;
multiDockerignore: boolean;
};

export type RepoContext = {
Expand Down
5 changes: 5 additions & 0 deletions tests/src/action.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const inputs: Partial<Inputs> = {
source: '/src',
layerCache: true,
defaultBranch: '',
multiDockerignore: true,
};

describe('src/action', () => {
Expand Down Expand Up @@ -135,6 +136,7 @@ describe('src/action', () => {
expect(pushStub.lastCall.args[1]).to.equal('/src');
expect(pushStub.lastCall.lastArg).to.deep.equal({
draft: false,
multiDockerignore: true,
noCache: true,
tags: {
sha: 'fba0317620597271695087c168c50d8c94975a29',
Expand Down Expand Up @@ -179,6 +181,7 @@ describe('src/action', () => {
await action.run(prContext, { ...inputs, createTag: true });
// Check that the last arg (buildOptions) does not contain draft: true
expect(pushStub.lastCall.lastArg).to.deep.equal({
multiDockerignore: true,
noCache: false,
tags: {
sha: 'fba0317620597271695087c168c50d8c94975a29',
Expand Down Expand Up @@ -234,6 +237,7 @@ describe('src/action', () => {
expect(pushStub.lastCall.lastArg).to.deep.equal({
noCache: false,
draft: false,
multiDockerignore: true,
tags: {
sha: 'fba0317620597271695087c168c50d8c94975a29',
},
Expand All @@ -256,6 +260,7 @@ describe('src/action', () => {
// Check that the last arg (buildOptions) does not contain draft: true
expect(pushStub.lastCall.lastArg).to.deep.equal({
noCache: false,
multiDockerignore: true,
draft: false,
tags: {
sha: 'fba0317620597271695087c168c50d8c94975a29',
Expand Down
4 changes: 3 additions & 1 deletion tests/src/balena-utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ describe('src/balena-utils', () => {
]);
});

it('Sets --draft or --nocache', async () => {
it('Sets --draft, --nocache and --multi-dockerignore', async () => {
setTimeout(() => {
mockProcess.emit('exit', 0); // make process exit
}, 500);
Expand All @@ -136,6 +136,7 @@ describe('src/balena-utils', () => {
await balenaUtils.push('org/fleet', '/tmp/source', false, {
noCache: true,
draft: true,
multiDockerignore: true,
tags: { sha: 'fba0317620597271695087c168c50d8c94975a29' },
});
} catch (e) {
Expand All @@ -152,6 +153,7 @@ describe('src/balena-utils', () => {
'fba0317620597271695087c168c50d8c94975a29',
'--draft',
'--nocache',
'--multi-dockerignore',
]);
});

Expand Down
2 changes: 2 additions & 0 deletions tests/src/main.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ describe('src/main', () => {
create_tag: true,
create_ref: false,
layer_cache: true,
multi_dockerignore: true,
}[inputName];
});
});
Expand Down Expand Up @@ -108,6 +109,7 @@ describe('src/main', () => {
githubToken: 'ghTokenExample',
layerCache: true,
defaultBranch: '',
multiDockerignore: true,
});
// Since github actions pass by default there's no need to check if the action passes
// So, let's check if the action correctly handles failures instead
Expand Down