Skip to content

Commit 4b2fc44

Browse files
authored
Merge pull request #26 from dhslove/codex/n2k-cloud-preserve-mac
N2K Cloud MAC 보존 및 릴리즈 checkout 기준 정리
2 parents a4d3f05 + 4a98fa7 commit 4b2fc44

3 files changed

Lines changed: 62 additions & 1 deletion

File tree

.github/workflows/build.yml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ permissions:
2222
contents: write
2323
actions: read
2424

25+
env:
26+
WORKFLOW_SOURCE_REF: ${{ github.event_name == 'workflow_run' && github.event.workflow_run.head_sha || github.ref }}
27+
2528
# NOTE (WinPE ISO)
2629
# - WinPE ISO artifacts are produced by the dedicated WinPE release workflows.
2730
# - This workflow optionally downloads the released WinPE ISO and bundles it into the final release artifacts.
@@ -40,6 +43,7 @@ jobs:
4043
- uses: actions/checkout@v4
4144
with:
4245
fetch-depth: 0
46+
ref: ${{ env.WORKFLOW_SOURCE_REF }}
4347

4448
- name: Install build deps (Rocky 9.6 vault)
4549
run: |
@@ -102,6 +106,7 @@ jobs:
102106
- uses: actions/checkout@v4
103107
with:
104108
fetch-depth: 0
109+
ref: ${{ env.WORKFLOW_SOURCE_REF }}
105110

106111
- name: Install build deps (hangctl, Rocky 9.6 vault)
107112
run: |
@@ -207,6 +212,7 @@ jobs:
207212
- uses: actions/checkout@v4
208213
with:
209214
fetch-depth: 0
215+
ref: ${{ env.WORKFLOW_SOURCE_REF }}
210216

211217
- name: Install build deps (ftctl, Rocky 9.6 vault)
212218
run: |
@@ -275,6 +281,7 @@ jobs:
275281
- uses: actions/checkout@v4
276282
with:
277283
fetch-depth: 0
284+
ref: ${{ env.WORKFLOW_SOURCE_REF }}
278285

279286
- name: Install build deps (v2k, Rocky ${{ matrix.host_os_minor }})
280287
run: |
@@ -554,6 +561,7 @@ jobs:
554561
- uses: actions/checkout@v4
555562
with:
556563
fetch-depth: 0
564+
ref: ${{ env.WORKFLOW_SOURCE_REF }}
557565

558566
- name: Install build deps (n2k, Rocky ${{ matrix.host_os_minor }})
559567
shell: bash
@@ -639,6 +647,7 @@ jobs:
639647
- uses: actions/checkout@v4
640648
with:
641649
fetch-depth: 0
650+
ref: ${{ env.WORKFLOW_SOURCE_REF }}
642651

643652
- name: Install build deps
644653
run: |
@@ -721,6 +730,9 @@ jobs:
721730
runs-on: windows-latest
722731
steps:
723732
- uses: actions/checkout@v4
733+
with:
734+
fetch-depth: 0
735+
ref: ${{ env.WORKFLOW_SOURCE_REF }}
724736

725737
- name: Install WiX v4
726738
run: dotnet tool install --global wix --version 4.*
@@ -751,13 +763,14 @@ jobs:
751763
uses: actions/checkout@v4
752764
with:
753765
fetch-depth: 0
754-
ref: ${{ github.event.workflow_run.head_sha }}
766+
ref: ${{ env.WORKFLOW_SOURCE_REF }}
755767

756768
- name: Checkout workflow_dispatch source
757769
if: ${{ github.event_name == 'workflow_dispatch' }}
758770
uses: actions/checkout@v4
759771
with:
760772
fetch-depth: 0
773+
ref: ${{ env.WORKFLOW_SOURCE_REF }}
761774

762775
- name: Resolve release context
763776
shell: bash
@@ -1990,6 +2003,7 @@ jobs:
19902003
uses: softprops/action-gh-release@v2
19912004
with:
19922005
tag_name: ${{ env.RELEASE_TAG }}
2006+
target_commitish: ${{ env.RELEASE_REF }}
19932007
body_path: release_notes.md
19942008
files: |
19952009
release/upload-assets/*
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# ABLESTACK-N2K Cloud Cutover Start Policy and Release Checkout Design
2+
3+
## Background
4+
5+
Cloud-managed N2K migrations use the same engine as the CLI wizard, but the Cloud agent wrapper previously forced Cloud target cutover to pass `--start`. The CLI already distinguishes the two target policies:
6+
7+
- `--apply`: deploy/import the target VM and leave it stopped.
8+
- `--apply --start`: deploy/import the target VM and start it after cutover.
9+
10+
This means a user can already request a stopped target VM from direct CLI or wizard mode, but the Cloud UI/API path could not express that preference.
11+
12+
The release workflow also had inconsistent checkout behavior during tag-triggered release builds. The release job checked out `workflow_run.head_sha`, while build jobs used the default checkout ref. If the default branch differs from the tag commit, generated artifacts can be built from a different commit than the release metadata.
13+
14+
## Design
15+
16+
### Cloud cutover policy
17+
18+
The Cloud API owns the user-facing choice and passes it to the host command as a boolean start policy. The KVM wrapper maps it to the engine flags:
19+
20+
- `starttargetvm=true`: pass `--start` and keep the current default behavior.
21+
- `starttargetvm=false`: pass `--apply` only, so Cloud creates the target VM but leaves it stopped.
22+
23+
CLI and wizard behavior remains unchanged. Existing wizard users can keep using `--apply` or `--start` directly.
24+
25+
### Release workflow checkout policy
26+
27+
All build jobs and the release job must check out the same source ref:
28+
29+
- `workflow_run`: use `github.event.workflow_run.head_sha`.
30+
- `workflow_dispatch`: use `github.ref`.
31+
32+
The final GitHub Release must also publish with `target_commitish` equal to the resolved checked-out commit.
33+
34+
## Compatibility
35+
36+
- Default behavior remains start-after-cutover for existing Cloud API/UI users.
37+
- Direct CLI and wizard mode keep their current semantics.
38+
- No database schema change is required.

lib/n2k/target_cloud.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,18 +225,27 @@ n2k_cloud_target_source_deploy_params_json() {
225225
elif ($s | test("scsi|lsilogic|pvscsi|buslogic")) then "scsi"
226226
else "" end;
227227
228+
def source_mac($vm):
229+
(($vm.nics // [])
230+
| map(.mac // .macAddress // .mac_address // "")
231+
| map((. // "") | tostring | ascii_downcase)
232+
| map(select(test("^([0-9a-f]{2}:){5}[0-9a-f]{2}$")))
233+
| first) // "";
234+
228235
(.source.vm // {}) as $vm
229236
| (($vm.cpu // 0) | tonumber? // 0) as $cpu
230237
| (($vm.memory_mb // 0) | tonumber? // 0) as $memory_mb
231238
| ((.target.cloud.cpu_speed // "1000") | tostring) as $cpu_speed
232239
| (($vm.firmware // "") | tostring | ascii_downcase) as $firmware
233240
| (($vm.secure_boot // false) == true) as $secure_boot
241+
| (source_mac($vm)) as $source_mac
234242
| (controller(.disks[0].controller.type // "")) as $root_controller
235243
| (controller((.disks[1:] // [] | map(.controller.type // "") | map(select((. | tostring | length) > 0)) | first) // "")) as $data_controller
236244
| {}
237245
+ (if $cpu > 0 then {"details[0].cpuNumber": ($cpu | floor | tostring)} else {} end)
238246
+ {"details[0].cpuSpeed": $cpu_speed}
239247
+ (if $memory_mb > 0 then {"details[0].memory": ($memory_mb | floor | tostring)} else {} end)
248+
+ (if ($source_mac | length) > 0 then {macaddress:$source_mac} else {} end)
240249
+ (if ($root_controller | length) > 0 then {"details[0].rootDiskController": $root_controller} else {} end)
241250
+ (if ($data_controller | length) > 0 then {"details[0].dataDiskController": $data_controller} else {} end)
242251
+ (

0 commit comments

Comments
 (0)