Skip to content

Commit aed523c

Browse files
jlebonPeaceRebel
authored andcommitted
Add cosa import
This command takes as argument a `containers-transport(5)`-style pullspec and creates a new cosa build dir from it. It essentially bridges the gap between coreos/fedora-coreos-config#3348 and the rest of the cosa pipeline. co-authored by: Bipin B Narayan <bbnaraya@redhat.com>
1 parent 35032cc commit aed523c

11 files changed

Lines changed: 298 additions & 19 deletions

File tree

cmd/coreos-assembler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313

1414
// commands we'd expect to use in the local dev path
1515
var buildCommands = []string{"init", "fetch", "build", "osbuild", "run", "prune", "clean", "list"}
16-
var advancedBuildCommands = []string{"buildfetch", "buildupload", "oc-adm-release", "push-container"}
16+
var advancedBuildCommands = []string{"import", "buildfetch", "buildupload", "oc-adm-release", "push-container"}
1717
var buildextendCommands = []string{"aliyun", "applehv", "aws", "azure", "digitalocean", "exoscale", "extensions-container", "gcp", "hyperv", "ibmcloud", "kubevirt", "live", "metal", "metal4k", "nutanix", "openstack", "oraclecloud", "qemu", "secex", "virtualbox", "vmware", "vultr"}
1818

1919
var utilityCommands = []string{"aws-replicate", "coreos-prune", "compress", "copy-container", "diff", "koji-upload", "kola", "push-container-manifest", "remote-build-container", "remote-session", "sign", "tag", "update-variant"}

go.mod

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,18 @@ require (
2929
github.com/digitalocean/go-qemu v0.0.0-20250212194115-ee9b0668d242
3030
github.com/digitalocean/godo v1.154.0
3131
github.com/frostschutz/go-fibmap v0.0.0-20160825162329-b32c231bfe6a
32+
github.com/gedex/inflector v0.0.0-20170307190818-16278e9db813
3233
github.com/google/uuid v1.6.0
3334
github.com/gophercloud/gophercloud v1.14.1
3435
github.com/gophercloud/utils v0.0.0-20231010081019-80377eca5d56
36+
github.com/idubinskiy/schematyper v0.0.0-20190118213059-f71b40dac30d
3537
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51
3638
github.com/kylelemons/godebug v1.1.0
3739
github.com/pborman/uuid v1.2.1
3840
github.com/pin/tftp v2.1.0+incompatible
3941
github.com/pkg/errors v0.9.1
4042
github.com/sirupsen/logrus v1.9.3
43+
github.com/smartystreets/goconvey v1.8.1
4144
github.com/spf13/cobra v1.9.1
4245
github.com/vincent-petithory/dataurl v1.0.0
4346
github.com/vishvananda/netlink v1.3.1
@@ -49,6 +52,7 @@ require (
4952
golang.org/x/oauth2 v0.30.0
5053
golang.org/x/term v0.32.0
5154
google.golang.org/api v0.238.0
55+
gopkg.in/alecthomas/kingpin.v2 v2.0.0-00010101000000-000000000000
5256
gopkg.in/yaml.v2 v2.4.0
5357
gopkg.in/yaml.v3 v3.0.1
5458
)
@@ -60,6 +64,7 @@ require (
6064
github.com/Azure/azure-sdk-for-go/sdk/internal v1.11.1 // indirect
6165
github.com/AzureAD/microsoft-authentication-library-for-go v1.4.2 // indirect
6266
github.com/IBM/go-sdk-core/v5 v5.19.0 // indirect
67+
github.com/alecthomas/units v0.0.0-20211218093645-b94a6e3cc137 // indirect
6368
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect
6469
github.com/clarketm/json v1.17.1 // indirect
6570
github.com/containers/image/v5 v5.34.2 // indirect
@@ -82,12 +87,14 @@ require (
8287
github.com/google/s2a-go v0.1.9 // indirect
8388
github.com/googleapis/enterprise-certificate-proxy v0.3.6 // indirect
8489
github.com/googleapis/gax-go/v2 v2.14.2 // indirect
90+
github.com/gopherjs/gopherjs v1.17.2 // indirect
8591
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
8692
github.com/hashicorp/go-retryablehttp v0.7.7 // indirect
8793
github.com/hashicorp/go-uuid v1.0.3 // indirect
8894
github.com/inconshreveable/mousetrap v1.1.0 // indirect
8995
github.com/jmespath/go-jmespath v0.4.0 // indirect
9096
github.com/json-iterator/go v1.1.12 // indirect
97+
github.com/jtolds/gls v4.20.0+incompatible // indirect
9198
github.com/leodido/go-urn v1.4.0 // indirect
9299
github.com/mitchellh/go-homedir v1.1.0 // indirect
93100
github.com/mitchellh/mapstructure v1.5.0 // indirect
@@ -98,10 +105,12 @@ require (
98105
github.com/opentracing/opentracing-go v1.2.1-0.20220228012449-10b1cf09e00b // indirect
99106
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c // indirect
100107
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
108+
github.com/smarty/assertions v1.15.0 // indirect
101109
github.com/spf13/pflag v1.0.6 // indirect
102110
github.com/stretchr/testify v1.10.0 // indirect
103111
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb // indirect
104112
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
113+
github.com/xhit/go-str2duration/v2 v2.1.0 // indirect
105114
go.mongodb.org/mongo-driver v1.17.3 // indirect
106115
go.opentelemetry.io/auto/sdk v1.1.0 // indirect
107116
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.61.0 // indirect

go.sum

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ github.com/IBM/go-sdk-core/v5 v5.19.0/go.mod h1:deZO1J5TSlU69bCnl/YV7nPxFZA2UEau
4444
github.com/IBM/ibm-cos-sdk-go v1.12.2 h1:71A4tDl8u6BZ548h71ecEe7fw5bBA7ECTVqYmeSQWQA=
4545
github.com/IBM/ibm-cos-sdk-go v1.12.2/go.mod h1:ODYcmrmdpjo5hVguq9RbD6xmC8xb1XZMG7NefUbJNcc=
4646
github.com/ajstarks/svgo v0.0.0-20180226025133-644b8db467af/go.mod h1:K08gAheRH3/J6wwsYMMT4xOr94bZjxIelGM0+d/wbFw=
47+
github.com/alecthomas/kingpin/v2 v2.4.0 h1:f48lwail6p8zpO1bC4TxtqACaGqHYA22qkHjHpqDjYY=
48+
github.com/alecthomas/kingpin/v2 v2.4.0/go.mod h1:0gyi0zQnjuFk8xrkNKamJoyUo382HRL7ATRpFZCw6tE=
49+
github.com/alecthomas/units v0.0.0-20211218093645-b94a6e3cc137 h1:s6gZFSlWYmbqAuRjVTiNNhvNRfY2Wxp9nhfyel4rklc=
50+
github.com/alecthomas/units v0.0.0-20211218093645-b94a6e3cc137/go.mod h1:OMCwj8VM1Kc9e19TLln2VL61YJF0x1XFtfdL4JdbSyE=
4751
github.com/aliyun/alibaba-cloud-sdk-go v1.63.107 h1:qagvUyrgOnBIlVRQWOyCZGVKUIYbMBdGdJ104vBpRFU=
4852
github.com/aliyun/alibaba-cloud-sdk-go v1.63.107/go.mod h1:SOSDHfe1kX91v3W5QiBsWSLqeLxImobbMX1mxrFHsVQ=
4953
github.com/aliyun/aliyun-oss-go-sdk v3.0.2+incompatible h1:8psS8a+wKfiLt1iVDX79F7Y6wUM49Lcha2FMXt4UM8g=
@@ -110,6 +114,8 @@ github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4
110114
github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw=
111115
github.com/gabriel-vasile/mimetype v1.4.8 h1:FfZ3gj38NjllZIeJAmMhr+qKL8Wu+nOoI3GqacKw1NM=
112116
github.com/gabriel-vasile/mimetype v1.4.8/go.mod h1:ByKUIKGjh1ODkGM1asKUbQZOLGrPjydw3hYPU2YU9t8=
117+
github.com/gedex/inflector v0.0.0-20170307190818-16278e9db813 h1:Uc+IZ7gYqAf/rSGFplbWBSHaGolEQlNLgMgSE3ccnIQ=
118+
github.com/gedex/inflector v0.0.0-20170307190818-16278e9db813/go.mod h1:P+oSoE9yhSRvsmYyZsshflcR6ePWYLql6UU1amW13IM=
113119
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
114120
github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
115121
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
@@ -186,6 +192,8 @@ github.com/gophercloud/gophercloud v1.14.1 h1:DTCNaTVGl8/cFu58O1JwWgis9gtISAFONq
186192
github.com/gophercloud/gophercloud v1.14.1/go.mod h1:aAVqcocTSXh2vYFZ1JTvx4EQmfgzxRcNupUfxZbBNDM=
187193
github.com/gophercloud/utils v0.0.0-20231010081019-80377eca5d56 h1:sH7xkTfYzxIEgzq1tDHIMKRh1vThOEOGNsettdEeLbE=
188194
github.com/gophercloud/utils v0.0.0-20231010081019-80377eca5d56/go.mod h1:VSalo4adEk+3sNkmVJLnhHoOyOYYS8sTWLG4mv5BKto=
195+
github.com/gopherjs/gopherjs v1.17.2 h1:fQnZVsXk8uxXIStYb0N4bGk7jeyTalG/wsZjQ25dO0g=
196+
github.com/gopherjs/gopherjs v1.17.2/go.mod h1:pRRIvn/QzFLrKfvEz3qUuEhtE/zLCWfreZ6J5gM2i+k=
189197
github.com/hashicorp/go-cleanhttp v0.5.2 h1:035FKYIWjmULyFRBKPs8TBQoi0x6d9G4xc9neXJWAZQ=
190198
github.com/hashicorp/go-cleanhttp v0.5.2/go.mod h1:kO/YDlP8L1346E6Sodw+PrpBSV4/SoxCXGY6BqNFT48=
191199
github.com/hashicorp/go-hclog v1.6.3 h1:Qr2kF+eVWjTiYmU7Y31tYlP1h0q/X3Nl3tPGdaB11/k=
@@ -196,6 +204,8 @@ github.com/hashicorp/go-uuid v1.0.3 h1:2gKiV6YVmrJ1i2CKKa9obLvRieoRGviZFL26PcT/C
196204
github.com/hashicorp/go-uuid v1.0.3/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
197205
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
198206
github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
207+
github.com/idubinskiy/schematyper v0.0.0-20190118213059-f71b40dac30d h1:sQbbvtUoen3Tfl9G/079tXeqniwPH6TgM/lU4y7lQN8=
208+
github.com/idubinskiy/schematyper v0.0.0-20190118213059-f71b40dac30d/go.mod h1:xVHEhsiSJJnT0jlcQpQUg+GyoLf0i0xciM1kqWTGT58=
199209
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
200210
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
201211
github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg=
@@ -204,6 +214,8 @@ github.com/jmespath/go-jmespath/internal/testify v1.5.1 h1:shLQSRRSCCPj3f2gpwzGw
204214
github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U=
205215
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
206216
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
217+
github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo=
218+
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
207219
github.com/jung-kurt/gofpdf v1.0.3-0.20190309125859-24315acbbda5/go.mod h1:7Id9E/uU8ce6rXgefFLlgrJj/GYY22cpxn+r32jIOes=
208220
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 h1:Z9n2FFNUXsshfwJMBgNA0RU6/i7WVaAegv3PtuIHPMs=
209221
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51/go.mod h1:CzGEWj7cYgsdH8dAjBGEr58BoE7ScuLd+fwFZ44+/x8=
@@ -304,6 +316,10 @@ github.com/rogpeppe/go-internal v1.13.1/go.mod h1:uMEvuHeurkdAXX61udpOXGD/AzZDWN
304316
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
305317
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
306318
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
319+
github.com/smarty/assertions v1.15.0 h1:cR//PqUBUiQRakZWqBiFFQ9wb8emQGDb0HeGdqGByCY=
320+
github.com/smarty/assertions v1.15.0/go.mod h1:yABtdzeQs6l1brC900WlRNwj6ZR55d7B+E8C6HtKdec=
321+
github.com/smartystreets/goconvey v1.8.1 h1:qGjIddxOk4grTu9JPOU31tVfq3cNdBlNa5sSznIX1xY=
322+
github.com/smartystreets/goconvey v1.8.1/go.mod h1:+/u4qLyY6x1jReYOp7GOM2FSt8aP9CzCZL03bI28W60=
307323
github.com/spf13/cobra v1.9.1 h1:CXSaggrXdbHK9CF+8ywj8Amf7PBRmPCOJugH954Nnlo=
308324
github.com/spf13/cobra v1.9.1/go.mod h1:nDyEzZ8ogv936Cinf6g1RU9MRY64Ir93oCnqb9wxYW0=
309325
github.com/spf13/pflag v1.0.6 h1:jFzHGLGAlb3ruxLB8MhbI6A8+AQX/2eW4qeyNZXNp2o=
@@ -312,6 +328,7 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+
312328
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
313329
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
314330
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
331+
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
315332
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
316333
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
317334
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
@@ -343,6 +360,8 @@ github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 h1:EzJWgHo
343360
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415/go.mod h1:GwrjFmJcFw6At/Gs6z4yjiIwzuJ1/+UwLxMQDVQXShQ=
344361
github.com/xeipuuv/gojsonschema v1.2.0 h1:LhYJRs+L4fBtjZUfuSZIKGeVu0QRy8e5Xi7D17UxZ74=
345362
github.com/xeipuuv/gojsonschema v1.2.0/go.mod h1:anYRn/JVcOK2ZgGU+IjEV4nwlhoK5sQluxsYJ78Id3Y=
363+
github.com/xhit/go-str2duration/v2 v2.1.0 h1:lxklc02Drh6ynqX+DdPyp5pCKLUQpRT8bp8Ydu2Bstc=
364+
github.com/xhit/go-str2duration/v2 v2.1.0/go.mod h1:ohY8p+0f07DiV6Em5LKB0s2YpLtXVyJfNt1+BlmyAsU=
346365
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d/go.mod h1:rHwXgn7JulP+udvsHwJoVG1YGAP6VLg4y9I5dyZdqmA=
347366
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
348367
github.com/yuin/goldmark v1.4.1/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=

pkg/builds/cosa_v1.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package builds
22

33
// generated by 'make schema'
4-
// source hash: 4bb5641ee8c32b122c412cbaefe3d068685ea6cbffcf3162e600a01268c92146
4+
// source hash: e7be69a1b23b4c4fdeb43f75c502c9ecd56abb618783ba15cc804adc51e4dcc3
55

66
type AdvisoryDiff []AdvisoryDiffItems
77

@@ -56,6 +56,7 @@ type Build struct {
5656
CosaDelayedMetaMerge bool `json:"coreos-assembler.delayed-meta-merge,omitempty"`
5757
CosaImageChecksum string `json:"coreos-assembler.image-config-checksum,omitempty"`
5858
CosaImageVersion int `json:"coreos-assembler.image-genver,omitempty"`
59+
CosaImportedOciImage bool `json:"coreos-assembler.oci-imported,omitempty"`
5960
Extensions *Extensions `json:"extensions,omitempty"`
6061
ExtensionsContainer *PrimaryImage `json:"extensions-container,omitempty"`
6162
FedoraCoreOsParentCommit string `json:"fedora-coreos.parent-commit,omitempty"`
@@ -64,15 +65,15 @@ type Build struct {
6465
GitDirty string `json:"coreos-assembler.config-dirty,omitempty"`
6566
IbmCloud []Cloudartifact `json:"ibmcloud,omitempty"`
6667
ImageInputChecksum string `json:"coreos-assembler.image-input-checksum,omitempty"`
67-
InputHashOfTheRpmOstree string `json:"rpm-ostree-inputhash"`
68+
InputHashOfTheRpmOstree string `json:"rpm-ostree-inputhash,omitempty"`
6869
Koji *Koji `json:"koji,omitempty"`
6970
KubevirtContainer *PrimaryImage `json:"kubevirt,omitempty"`
7071
MetaStamp float64 `json:"coreos-assembler.meta-stamp,omitempty"`
7172
Name string `json:"name"`
7273
Oscontainer *PrimaryImage `json:"oscontainer,omitempty"`
73-
OstreeCommit string `json:"ostree-commit"`
74+
OstreeCommit string `json:"ostree-commit,omitempty"`
7475
OstreeContentBytesWritten int `json:"ostree-content-bytes-written,omitempty"`
75-
OstreeContentChecksum string `json:"ostree-content-checksum"`
76+
OstreeContentChecksum string `json:"ostree-content-checksum,omitempty"`
7677
OstreeNCacheHits int `json:"ostree-n-cache-hits,omitempty"`
7778
OstreeNContentTotal int `json:"ostree-n-content-total,omitempty"`
7879
OstreeNContentWritten int `json:"ostree-n-content-written,omitempty"`

pkg/builds/schema_doc.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Generated by ./generate-schema.sh
2-
// Source hash: 4bb5641ee8c32b122c412cbaefe3d068685ea6cbffcf3162e600a01268c92146
2+
// Source hash: e7be69a1b23b4c4fdeb43f75c502c9ecd56abb618783ba15cc804adc51e4dcc3
33
// DO NOT EDIT
44

55
package builds
@@ -254,11 +254,8 @@ var generatedSchemaJSON = `{
254254
"required": [
255255
"buildid",
256256
"name",
257-
"ostree-commit",
258-
"ostree-content-checksum",
259257
"ostree-timestamp",
260-
"ostree-version",
261-
"rpm-ostree-inputhash"
258+
"ostree-version"
262259
],
263260
"optional": [
264261
"aliyun",
@@ -297,6 +294,7 @@ var generatedSchemaJSON = `{
297294
"coreos-assembler.meta-stamp",
298295
"coreos-assembler.overrides-active",
299296
"coreos-assembler.yumrepos-git",
297+
"coreos-assembeler.oci-imported",
300298
"fedora-coreos.parent-commit",
301299
"fedora-coreos.parent-version",
302300
"ref"
@@ -378,6 +376,12 @@ var generatedSchemaJSON = `{
378376
"default": "",
379377
"minLength": 1
380378
},
379+
"coreos-assembler.oci-imported": {
380+
"$id": "#/properties/coreos-assembler.oci-imported",
381+
"type": "boolean",
382+
"title": "COSA imported OCI image ",
383+
"default": "False"
384+
},
381385
"coreos-assembler.code-source": {
382386
"$id": "#/properties/coreos-assembler.code-source",
383387
"type": "string",

src/cmd-import

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
#!/usr/bin/python3
2+
3+
import argparse
4+
import json
5+
import os
6+
import subprocess
7+
import tempfile
8+
import shutil
9+
import sys
10+
from stat import (
11+
S_IREAD,
12+
S_IRGRP,
13+
S_IROTH)
14+
from cosalib.builds import Builds
15+
from cosalib.cmdlib import (
16+
get_basearch,
17+
sha256sum_file)
18+
19+
VALID_NAMES = ["fedora-coreos", "rhcos", "scos"]
20+
21+
22+
def main():
23+
args = parse_args()
24+
with tempfile.TemporaryDirectory(prefix='cosa-import-', dir='tmp') as tmpd:
25+
populate_build_dir(args, tmpd)
26+
sys.exit()
27+
28+
29+
def parse_args():
30+
parser = argparse.ArgumentParser(prog='cosa import')
31+
parser.add_argument("srcimg", metavar='IMAGE',
32+
help="image to import (containers-transports(5) format)")
33+
return parser.parse_args()
34+
35+
36+
def populate_build_dir(args, tmpd):
37+
target_ociarchive = os.path.join(tmpd, "out.ociarchive")
38+
import_oci_archive(args, target_ociarchive)
39+
metadata = inspect_oci_archive(target_ociarchive)
40+
name = metadata['Labels']['name']
41+
buildid = metadata['Labels']['org.opencontainers.image.version']
42+
arch = get_basearch()
43+
44+
os.makedirs(f'builds/{buildid}/{arch}/', exist_ok=True)
45+
46+
manifest_metadata = generate_manifest_json(target_ociarchive, name, buildid, arch)
47+
48+
meta_json = generate_meta_json(target_ociarchive, metadata, manifest_metadata, name)
49+
50+
archive_path = meta_json['images']['ostree']['path']
51+
52+
# Move ociarchive to build dir
53+
shutil.move(target_ociarchive, f'builds/{buildid}/{arch}/{archive_path}')
54+
55+
# Symlink build to latest
56+
if os.path.exists('builds/latest'):
57+
os.remove('builds/latest')
58+
os.symlink(f'{buildid}', 'builds/latest', target_is_directory=True)
59+
60+
builds = Builds()
61+
update_builds_json(builds, buildid, arch)
62+
63+
64+
def update_builds_json(builds, buildid, arch):
65+
builds.insert_build(buildid, arch)
66+
builds.bump_timestamp()
67+
builds.flush()
68+
69+
70+
def import_oci_archive(args, target):
71+
subprocess.check_call(['skopeo', 'copy', args.srcimg,
72+
f"oci-archive:{target}"])
73+
74+
75+
def inspect_oci_archive(image):
76+
out = subprocess.check_output(['skopeo', 'inspect',
77+
f'oci-archive:{image}'])
78+
return json.loads(out)
79+
80+
81+
def generate_manifest_json(ociarchive, name, buildid, arch):
82+
manifest = subprocess.check_output(["skopeo", "inspect", "--raw", f"oci-archive:{ociarchive}"])
83+
84+
ostree_oci_manifest_path = f"{name}-{buildid}-ostree.{arch}-manifest.json"
85+
manifest_json_dest = f'builds/{buildid}/{arch}/{ostree_oci_manifest_path}'
86+
87+
manifest_json_sha256 = None
88+
manifest_json_size = None
89+
with open(manifest_json_dest, 'wb') as manifest_json:
90+
manifest_json.write(manifest)
91+
os.fchmod(manifest_json.fileno(), S_IREAD | S_IRGRP | S_IROTH)
92+
93+
manifest_json_sha256 = sha256sum_file(manifest_json_dest)
94+
manifest_json_size = os.path.getsize(manifest_json_dest)
95+
96+
manifest_metadata = {
97+
'path': ostree_oci_manifest_path,
98+
'sha256': manifest_json_sha256,
99+
'size': manifest_json_size,
100+
"skip-compression": True,
101+
}
102+
103+
return manifest_metadata
104+
105+
106+
def generate_meta_json(ociarchive, metadata, oci_manifest, name):
107+
archive_sha256sum = sha256sum_file(ociarchive)
108+
109+
# let raise if missing
110+
assert metadata['Labels']['containers.bootc'] == '1'
111+
112+
buildid = metadata['Labels']['org.opencontainers.image.version']
113+
arch = get_basearch()
114+
115+
meta_json = {
116+
'ostree-version': buildid, # proxy version label
117+
'buildid': buildid, # also version label
118+
'coreos-assembler.build-timestamp': metadata['Created'], # proxy OCI build timestamp
119+
'coreos-assembler.oci-imported': True,
120+
'name': name,
121+
'ostree-timestamp': metadata['Created'],
122+
'images': {
123+
'ostree': {
124+
"path": f"{name}-{buildid}-ostree.{arch}.ociarchive",
125+
"sha256": archive_sha256sum,
126+
"skip-compression": True
127+
},
128+
'oci-manifest': oci_manifest,
129+
},
130+
'coreos-assembler.basearch': arch,
131+
}
132+
133+
with open(f'builds/{buildid}/{arch}/meta.json', 'w') as meta_file:
134+
json.dump(meta_json, meta_file, indent=4)
135+
136+
return meta_json
137+
138+
139+
if __name__ == '__main__':
140+
main()

0 commit comments

Comments
 (0)