Skip to content

Create Plugin: Add docker-compose migration for extending from .config #1621

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

Merged
merged 12 commits into from
May 5, 2025

Conversation

jackw
Copy link
Collaborator

@jackw jackw commented Mar 14, 2025

What this PR does / why we need it:
This PR introduces the first migration script that aims to update plugins ./docker-compose.yaml to extend from the ./.config/docker-compose-base.yaml.

It can be tested locally by passing --experimental-updates along with the update command.

Which issue(s) this PR fixes:

Fixes #

Special notes for your reviewer:

📦 Published PR as canary version: Canary Versions

✨ Test out this PR locally via:

npm install @libs/[email protected]
npm install @grafana/[email protected]
npm install @grafana/[email protected]
npm install @grafana/[email protected]
npm install @grafana/[email protected]
npm install @grafana/[email protected]
# or 
yarn add @libs/[email protected]
yarn add @grafana/[email protected]
yarn add @grafana/[email protected]
yarn add @grafana/[email protected]
yarn add @grafana/[email protected]
yarn add @grafana/[email protected]

@jackw jackw added create-plugin related to the create-plugin tool patch Increment the patch version when merged release Create a release when this pr is merged labels Mar 14, 2025
@jackw jackw self-assigned this Mar 14, 2025
@jackw jackw requested a review from a team as a code owner March 14, 2025 17:26
@jackw jackw requested a review from oshirohugo March 14, 2025 17:26
@jackw jackw moved this from 📬 Triage to 🧑‍💻 In development in Plugins Platform / Grafana Community Mar 14, 2025
Copy link
Contributor

github-actions bot commented Mar 14, 2025

Hello! 👋 This repository uses Auto for releasing packages using PR labels.

✨ This PR can be merged and will trigger a new patch release.
NOTE: When merging a PR with the release label please avoid merging another PR. For further information see here.

@jackw jackw force-pushed the jackw/docker-compose-migration branch from 084e33e to 236773a Compare April 10, 2025 14:42
@jackw jackw requested a review from a team as a code owner April 10, 2025 14:42
@jackw jackw requested review from andresmgot and s4kh April 10, 2025 14:42
import migrate from './001-update-grafana-compose-extend.js';
import { parse, stringify } from 'yaml';

describe('001-update-grafana-compose-extend', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

the only thing that came to my mind is that this also preserves comments in the file. could you add a test case for that?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks for taking a look at this @academo. I've updated the migration to use the parse document and visit apis from yaml which preserves comments.

@jackw jackw force-pushed the jackw/docker-compose-migration branch from eaeaecf to 92bf12b Compare April 15, 2025 13:00
@jackw jackw moved this from 🧑‍💻 In development to 🔬 In review in Plugins Platform / Grafana Community Apr 16, 2025
@jackw jackw force-pushed the jackw/docker-compose-migration branch 2 times, most recently from bd154dc to 39fa6a4 Compare April 17, 2025 10:35
Copy link
Contributor

@andresmgot andresmgot left a comment

Choose a reason for hiding this comment

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

I haven't tried this but the testing is pretty extensive so LGTM!

Comment on lines 26 to 51
visit(composeData, {
Pair: ((
_key: unknown,
pair: Pair<unknown, unknown>,
path: ReadonlyArray<Node | Document | Pair<unknown, unknown>>
) => {
const keyPath: string[] = [];
for (const p of path) {
if (p instanceof Pair && p.key instanceof Scalar) {
keyPath.push(p.key.value as string);
}
}

if (pair.key instanceof Scalar) {
keyPath.push(pair.key.value as string);
}

if (keyPath[0] === 'services' && keyPath[1] === 'grafana') {
const baseValue = baseComposeData.getIn(keyPath);

if (baseValue && JSON.stringify(pair.value) === JSON.stringify(baseValue)) {
composeData.deleteIn(keyPath);
}
}
}) as visitorFn<Pair<unknown, unknown>>,
});
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe a comment here of what the goal of this block is would help

Comment on lines 118 to 134
composeData.deleteIn(['services', 'grafana', 'build', 'context']);
const build = composeData.getIn(['services', 'grafana', 'build']);
if (build instanceof YAMLMap && build.items?.length === 0) {
composeData.deleteIn(['services', 'grafana', 'build']);
}

const volumes = composeData.getIn(['services', 'grafana', 'volumes']);
if (volumes instanceof YAMLSeq && volumes.items.length === 0) {
composeData.deleteIn(['services', 'grafana', 'volumes']);
}

composeData.addIn(['services', 'grafana', 'extends'], {
file: '.config/docker-compose-base.yaml',
service: 'grafana',
});

context.updateFile('./docker-compose.yaml', stringify(composeData, { lineWidth: 120, singleQuote: true }));
Copy link
Contributor

Choose a reason for hiding this comment

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

same here, some comments explaining what's going on would help reading this

@jackw jackw force-pushed the jackw/docker-compose-migration branch from 39fa6a4 to aacb95e Compare May 5, 2025 07:27
@jackw jackw enabled auto-merge (squash) May 5, 2025 08:24
@jackw jackw merged commit c793188 into main May 5, 2025
18 checks passed
@jackw jackw deleted the jackw/docker-compose-migration branch May 5, 2025 08:25
@github-project-automation github-project-automation bot moved this from 🔬 In review to 🚀 Shipped in Plugins Platform / Grafana Community May 5, 2025
@grafana-plugins-platform-bot
Copy link
Contributor

@grafana-plugins-platform-bot grafana-plugins-platform-bot bot added the released This issue/pull request has been released. label May 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
create-plugin related to the create-plugin tool patch Increment the patch version when merged release Create a release when this pr is merged released This issue/pull request has been released.
Projects
Development

Successfully merging this pull request may close these issues.

3 participants