-
Notifications
You must be signed in to change notification settings - Fork 31
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
Conversation
084e33e
to
236773a
Compare
import migrate from './001-update-grafana-compose-extend.js'; | ||
import { parse, stringify } from 'yaml'; | ||
|
||
describe('001-update-grafana-compose-extend', () => { |
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.
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?
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.
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.
eaeaecf
to
92bf12b
Compare
bd154dc
to
39fa6a4
Compare
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.
I haven't tried this but the testing is pretty extensive so LGTM!
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>>, | ||
}); |
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.
maybe a comment here of what the goal of this block is would help
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 })); |
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.
same here, some comments explaining what's going on would help reading this
…o extend from .config
…env and tidy logic
…to preserve comments
39fa6a4
to
aacb95e
Compare
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: