build: add tool for managing repos
diff --git a/cmd/atmosphere-ci/image.go b/cmd/atmosphere-ci/image.go
new file mode 100644
index 0000000..492d2b9
--- /dev/null
+++ b/cmd/atmosphere-ci/image.go
@@ -0,0 +1,14 @@
+package main
+
+import (
+ "github.com/spf13/cobra"
+)
+
+var imageCmd = &cobra.Command{
+ Use: "image",
+ Short: "Image sub-commands",
+}
+
+func init() {
+ rootCmd.AddCommand(imageCmd)
+}
diff --git a/cmd/atmosphere-ci/image_repo.go b/cmd/atmosphere-ci/image_repo.go
new file mode 100644
index 0000000..2ab4d4a
--- /dev/null
+++ b/cmd/atmosphere-ci/image_repo.go
@@ -0,0 +1,14 @@
+package main
+
+import (
+ "github.com/spf13/cobra"
+)
+
+var imageRepoCmd = &cobra.Command{
+ Use: "repo",
+ Short: "Image repository sub-commands",
+}
+
+func init() {
+ imageCmd.AddCommand(imageRepoCmd)
+}
diff --git a/cmd/atmosphere-ci/image_repo_sync.go b/cmd/atmosphere-ci/image_repo_sync.go
new file mode 100644
index 0000000..e4f9667
--- /dev/null
+++ b/cmd/atmosphere-ci/image_repo_sync.go
@@ -0,0 +1,31 @@
+package main
+
+import (
+ "context"
+
+ log "github.com/sirupsen/logrus"
+ "github.com/spf13/cobra"
+ "github.com/vexxhost/atmosphere/internal/pkg/image_repositories"
+)
+
+var (
+ imageRepoSyncCmd = &cobra.Command{
+ Use: "sync [project]",
+ Short: "Sync image repository",
+ Args: cobra.MinimumNArgs(1),
+
+ Run: func(cmd *cobra.Command, args []string) {
+ ctx := context.TODO()
+
+ repo := image_repositories.NewImageRepository(args[0])
+ err := repo.Synchronize(ctx)
+ if err != nil {
+ log.Panic(err)
+ }
+ },
+ }
+)
+
+func init() {
+ imageRepoCmd.AddCommand(imageRepoSyncCmd)
+}
diff --git a/cmd/atmosphere-ci/main.go b/cmd/atmosphere-ci/main.go
new file mode 100644
index 0000000..48e4f2e
--- /dev/null
+++ b/cmd/atmosphere-ci/main.go
@@ -0,0 +1,20 @@
+package main
+
+import (
+ "fmt"
+ "os"
+
+ "github.com/spf13/cobra"
+)
+
+var rootCmd = &cobra.Command{
+ Use: "atmosphere-ci",
+ Short: "CLI tools for Atmosphere CI",
+}
+
+func main() {
+ if err := rootCmd.Execute(); err != nil {
+ fmt.Fprintln(os.Stderr, err)
+ os.Exit(1)
+ }
+}
diff --git a/go.mod b/go.mod
index 70f8808..9269faa 100644
--- a/go.mod
+++ b/go.mod
@@ -3,11 +3,44 @@
go 1.19
require (
+ code.gitea.io/sdk/gitea v0.15.1
+ github.com/go-git/go-billy/v5 v5.3.1
+ github.com/go-git/go-git/v5 v5.4.2
+ github.com/goccy/go-yaml v1.9.5
+ github.com/google/go-github/v47 v47.0.0
+ github.com/sirupsen/logrus v1.9.0
+ github.com/spf13/cobra v1.5.0
github.com/stretchr/testify v1.8.0
+ golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be
gopkg.in/yaml.v3 v3.0.1
)
require (
+ github.com/Microsoft/go-winio v0.4.16 // indirect
+ github.com/ProtonMail/go-crypto v0.0.0-20210428141323-04723f9f07d7 // indirect
+ github.com/acomagu/bufpipe v1.0.3 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
+ github.com/emirpasic/gods v1.12.0 // indirect
+ github.com/fatih/color v1.10.0 // indirect
+ github.com/go-git/gcfg v1.5.0 // indirect
+ github.com/golang/protobuf v1.3.2 // indirect
+ github.com/google/go-querystring v1.1.0 // indirect
+ github.com/hashicorp/go-version v1.2.1 // indirect
+ github.com/imdario/mergo v0.3.12 // indirect
+ github.com/inconshreveable/mousetrap v1.0.0 // indirect
+ github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
+ github.com/kevinburke/ssh_config v0.0.0-20201106050909-4977a11b4351 // indirect
+ github.com/mattn/go-colorable v0.1.8 // indirect
+ github.com/mattn/go-isatty v0.0.12 // indirect
+ github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
+ github.com/sergi/go-diff v1.1.0 // indirect
+ github.com/spf13/pflag v1.0.5 // indirect
+ github.com/xanzy/ssh-agent v0.3.0 // indirect
+ golang.org/x/crypto v0.0.0-20211202192323-5770296d904e // indirect
+ golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2 // indirect
+ golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 // indirect
+ golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
+ google.golang.org/appengine v1.6.7 // indirect
+ gopkg.in/warnings.v0 v0.1.2 // indirect
)
diff --git a/go.sum b/go.sum
index 5164829..e4faaad 100644
--- a/go.sum
+++ b/go.sum
@@ -1,15 +1,177 @@
+code.gitea.io/gitea-vet v0.2.1/go.mod h1:zcNbT/aJEmivCAhfmkHOlT645KNOf9W2KnkLgFjGGfE=
+code.gitea.io/sdk/gitea v0.15.1 h1:WJreC7YYuxbn0UDaPuWIe/mtiNKTvLN8MLkaw71yx/M=
+code.gitea.io/sdk/gitea v0.15.1/go.mod h1:klY2LVI3s3NChzIk/MzMn7G1FHrfU7qd63iSMVoHRBA=
+github.com/Microsoft/go-winio v0.4.14/go.mod h1:qXqCSQ3Xa7+6tgxaGTIe4Kpcdsi+P8jBhyzoq1bpyYA=
+github.com/Microsoft/go-winio v0.4.16 h1:FtSW/jqD+l4ba5iPBj9CODVtgfYAD8w2wS923g/cFDk=
+github.com/Microsoft/go-winio v0.4.16/go.mod h1:XB6nPKklQyQ7GC9LdcBEcBl8PF76WugXOPRXwdLnMv0=
+github.com/ProtonMail/go-crypto v0.0.0-20210428141323-04723f9f07d7 h1:YoJbenK9C67SkzkDfmQuVln04ygHj3vjZfd9FL+GmQQ=
+github.com/ProtonMail/go-crypto v0.0.0-20210428141323-04723f9f07d7/go.mod h1:z4/9nQmJSSwwds7ejkxaJwO37dru3geImFUdJlaLzQo=
+github.com/acomagu/bufpipe v1.0.3 h1:fxAGrHZTgQ9w5QqVItgzwj235/uYZYgbXitB+dLupOk=
+github.com/acomagu/bufpipe v1.0.3/go.mod h1:mxdxdup/WdsKVreO5GpW4+M/1CE2sMG4jeGJ2sYmHc4=
+github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239 h1:kFOfPq6dUM1hTo4JG6LR5AXSUEsOjtdm0kw0FtQtMJA=
+github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239/go.mod h1:2FmKhYUyUczH0OGQWaF5ceTx0UBShxjsH6f8oGKYe2c=
+github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio=
+github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs=
+github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
+github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
+github.com/emirpasic/gods v1.12.0 h1:QAUIPSaCu4G+POclxeqb3F+WPpdKqFGlw36+yOzGlrg=
+github.com/emirpasic/gods v1.12.0/go.mod h1:YfzfFFoVP/catgzJb4IKIqXjX78Ha8FMSDh3ymbK86o=
+github.com/fatih/color v1.10.0 h1:s36xzo75JdqLaaWoiEHk767eHiwo0598uUxyfiPkDsg=
+github.com/fatih/color v1.10.0/go.mod h1:ELkj/draVOlAH/xkhN6mQ50Qd0MPOk5AAr3maGEBuJM=
+github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc=
+github.com/gliderlabs/ssh v0.2.2 h1:6zsha5zo/TWhRhwqCD3+EarCAgZ2yN28ipRnGPnwkI0=
+github.com/gliderlabs/ssh v0.2.2/go.mod h1:U7qILu1NlMHj9FlMhZLlkCdDnU1DBEAqr0aevW3Awn0=
+github.com/go-git/gcfg v1.5.0 h1:Q5ViNfGF8zFgyJWPqYwA7qGFoMTEiBmdlkcfRmpIMa4=
+github.com/go-git/gcfg v1.5.0/go.mod h1:5m20vg6GwYabIxaOonVkTdrILxQMpEShl1xiMF4ua+E=
+github.com/go-git/go-billy/v5 v5.2.0/go.mod h1:pmpqyWchKfYfrkb/UVH4otLvyi/5gJlGI4Hb3ZqZ3W0=
+github.com/go-git/go-billy/v5 v5.3.1 h1:CPiOUAzKtMRvolEKw+bG1PLRpT7D3LIs3/3ey4Aiu34=
+github.com/go-git/go-billy/v5 v5.3.1/go.mod h1:pmpqyWchKfYfrkb/UVH4otLvyi/5gJlGI4Hb3ZqZ3W0=
+github.com/go-git/go-git-fixtures/v4 v4.2.1 h1:n9gGL1Ct/yIw+nfsfr8s4+sbhT+Ncu2SubfXjIWgci8=
+github.com/go-git/go-git-fixtures/v4 v4.2.1/go.mod h1:K8zd3kDUAykwTdDCr+I0per6Y6vMiRR/nnVTBtavnB0=
+github.com/go-git/go-git/v5 v5.4.2 h1:BXyZu9t0VkbiHtqrsvdq39UDhGJTl1h55VW6CSC4aY4=
+github.com/go-git/go-git/v5 v5.4.2/go.mod h1:gQ1kArt6d+n+BGd+/B/I74HwRTLhth2+zti4ihgckDc=
+github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
+github.com/go-playground/locales v0.13.0 h1:HyWk6mgj5qFqCT5fjGBuRArbVDfE4hi8+e8ceBS/t7Q=
+github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTMfnGwq/HNwmWNS8=
+github.com/go-playground/universal-translator v0.17.0 h1:icxd5fm+REJzpZx7ZfpaD876Lmtgy7VtROAbHHXk8no=
+github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+Scu5vgOQjsIJAF8j9muTVoKLVtA=
+github.com/go-playground/validator/v10 v10.4.1 h1:pH2c5ADXtd66mxoE0Zm9SUhxE20r7aM3F26W0hOn+GE=
+github.com/go-playground/validator/v10 v10.4.1/go.mod h1:nlOn6nFhuKACm19sB/8EGNn9GlaMV7XkbRSipzJ0Ii4=
+github.com/goccy/go-yaml v1.9.5 h1:Eh/+3uk9kLxG4koCX6lRMAPS1OaMSAi+FJcya0INdB0=
+github.com/goccy/go-yaml v1.9.5/go.mod h1:U/jl18uSupI5rdI2jmuCswEA2htH9eXfferR3KfscvA=
+github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
+github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs=
+github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
+github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
+github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
+github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg=
+github.com/google/go-github/v47 v47.0.0 h1:eQap5bIRZibukP0VhngWgpuM0zhY4xntqOzn6DhdkE4=
+github.com/google/go-github/v47 v47.0.0/go.mod h1:DRjdvizXE876j0YOZwInB1ESpOcU/xFBClNiQLSdorE=
+github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
+github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
+github.com/hashicorp/go-version v1.2.1 h1:zEfKbn2+PDgroKdiOzqiE8rsmLqU2uwi5PB5pBJ3TkI=
+github.com/hashicorp/go-version v1.2.1/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
+github.com/imdario/mergo v0.3.12 h1:b6R2BslTbIEToALKP7LxUvijTsNI9TAe80pLWN2g/HU=
+github.com/imdario/mergo v0.3.12/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA=
+github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
+github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
+github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A=
+github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo=
+github.com/jessevdk/go-flags v1.5.0/go.mod h1:Fw0T6WPc1dYxT4mKEZRfG5kJhaTDP9pj1c2EWnYs/m4=
+github.com/kevinburke/ssh_config v0.0.0-20201106050909-4977a11b4351 h1:DowS9hvgyYSX4TO5NpyC606/Z4SxnNYbT+WX27or6Ck=
+github.com/kevinburke/ssh_config v0.0.0-20201106050909-4977a11b4351/go.mod h1:CT57kijsi8u/K/BOFA39wgDQJ9CxiF4nAY/ojJ6r6mM=
+github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
+github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
+github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=
+github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
+github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
+github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
+github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
+github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
+github.com/leodido/go-urn v1.2.0 h1:hpXL4XnriNwQ/ABnpepYM/1vCLWNDfUNts8dX3xTG6Y=
+github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII=
+github.com/matryer/is v1.2.0 h1:92UTHpy8CDwaJ08GqLDzhhuixiBUUD1p3AU6PHddz4A=
+github.com/matryer/is v1.2.0/go.mod h1:2fLPjFQM9rhQ15aVEtbuwhJinnOqrmgXPNdZsdwlWXA=
+github.com/mattn/go-colorable v0.1.8 h1:c1ghPdyEDarC70ftn0y+A/Ee++9zz8ljHG1b13eJ0s8=
+github.com/mattn/go-colorable v0.1.8/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
+github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY=
+github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
+github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
+github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
+github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
+github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
+github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
+github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
+github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
+github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
+github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
+github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q=
+github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0=
+github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
+github.com/spf13/cobra v1.5.0 h1:X+jTBEBqF0bHN+9cSMgmfuvv2VHJ9ezmFNf9Y/XstYU=
+github.com/spf13/cobra v1.5.0/go.mod h1:dWXEIy2H428czQCjInthrTRUg7yKbok+2Qi/yBIJoUM=
+github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
+github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
+github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
+github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
+github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
+github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
-gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
+github.com/xanzy/ssh-agent v0.3.0 h1:wUMzuKtKilRgBAD1sUb8gOwwRr2FGoBVumcjoOACClI=
+github.com/xanzy/ssh-agent v0.3.0/go.mod h1:3s9xbODqPuuhK9JV1R321M/FlMZSBvE5aY6eAcqrDh0=
+github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
+golang.org/x/crypto v0.0.0-20190219172222-a4c6cb3142f2/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
+golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
+golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
+golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
+golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4=
+golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4=
+golang.org/x/crypto v0.0.0-20211202192323-5770296d904e h1:MUP6MR3rJ7Gk9LEia0LP2ytiH6MuCfs7qYz+47jGdD8=
+golang.org/x/crypto v0.0.0-20211202192323-5770296d904e/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
+golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
+golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
+golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks=
+golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
+golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
+golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
+golang.org/x/net v0.0.0-20210326060303-6b1517762897/go.mod h1:uSPa2vr4CLtc/ILN5odXGNXS6mhrKVzTaCXzk9m6W3k=
+golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2 h1:CIJ76btIcR3eFI5EgSo6k1qKw9KJexJuRLI9G7Hp5wE=
+golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
+golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be h1:vEDujvNQGv4jgYKudGeI/+DAX4Jffq6hpD55MmoEvKs=
+golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
+golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
+golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
+golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
+golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
+golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/sys v0.0.0-20210320140829-1e4c9ba3b0c4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/sys v0.0.0-20210324051608-47abb6519492/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/sys v0.0.0-20210502180810-71e4cd670f79/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 h1:0A+M6Uqn+Eje4kHMK80dtF3JCXC4ykBgQG4Fe06QRhQ=
+golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
+golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1 h1:v+OssWQX+hTHEmOBgwxdZxK4zHq3yOs8F9J7mk0PY8E=
+golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
+golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
+golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
+golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
+golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M=
+golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
+golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
+golang.org/x/tools v0.0.0-20200325010219-a49f79bcc224/go.mod h1:Sl4aGygMT6LrqrWclx+PTx3U+LnKx/seiNR+3G19Ar8=
+golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
+golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
+golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
+golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
+golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
+google.golang.org/appengine v1.6.7 h1:FZR1q0exgwxzPzp/aF+VccGrSfxfPpkBqjIIEq3ru6c=
+google.golang.org/appengine v1.6.7/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
+gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
+gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
+gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
+gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
+gopkg.in/warnings.v0 v0.1.2 h1:wFXVbFY8DY5/xOe1ECiWdKCzZlxgshcYVNkBHstARME=
+gopkg.in/warnings.v0 v0.1.2/go.mod h1:jksf8JmL6Qr/oQM2OXTHunEvvTAsrWBLb6OOjuVWRNI=
+gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
+gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
+gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
+gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
+gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
diff --git a/internal/pkg/image_repositories/build_workflow.go b/internal/pkg/image_repositories/build_workflow.go
new file mode 100644
index 0000000..ba40d9d
--- /dev/null
+++ b/internal/pkg/image_repositories/build_workflow.go
@@ -0,0 +1,138 @@
+package image_repositories
+
+import (
+ "fmt"
+ "strings"
+)
+
+var PROFILES map[string]string = map[string]string{
+ "cinder": "ceph qemu",
+ "nova": "ceph openvswitch configdrive qemu migration",
+ "neutron": "openvswitch vpn",
+ "keystone": "apache ldap openidc",
+ "horizon": "apache",
+ "monasca-api": "apache influxdb",
+ "ironic": "ipxe ipmi qemu tftp",
+ "glance": "ceph",
+ "monasca-persister": "influxdb",
+ "placement": "apache",
+}
+var DIST_PACAKGES map[string]string = map[string]string{
+ "heat": "curl",
+ "designate": "bind9utils",
+ "nova": "ovmf qemu-efi-aarch64",
+ "neutron": "jq ethtool lshw",
+ "monasca-agent": "iproute2 libvirt-clients lshw",
+ "ironic": "ethtool lshw iproute2",
+}
+var PIP_PACKAGES map[string]string = map[string]string{
+ "neutron": "neutron-vpnaas",
+ "monasca-agent": "libvirt-python python-glanceclient python-neutronclient python-novaclient py3nvml",
+ "horizon": "designate-dashboard heat-dashboard ironic-ui magnum-ui neutron-vpnaas-dashboard octavia-dashboard senlin-dashboard monasca-ui",
+ "ironic": "python-dracclient sushy",
+ "placement": "httplib2",
+}
+var PLATFORMS map[string]string = map[string]string{
+ "nova": "linux/amd64,linux/arm64",
+ "neutron": "linux/amd64,linux/arm64",
+}
+
+func NewBuildWorkflow(project string) *GithubWorkflow {
+ profiles := ""
+ if val, ok := PROFILES[project]; ok {
+ profiles = val
+ }
+
+ distPackages := ""
+ if val, ok := DIST_PACAKGES[project]; ok {
+ distPackages = val
+ }
+
+ pipPackages := ""
+ if val, ok := PIP_PACKAGES[project]; ok {
+ pipPackages = val
+ }
+
+ platforms := "linux/amd64"
+ if val, ok := PLATFORMS[project]; ok {
+ platforms = val
+ }
+
+ buildArgs := []string{
+ "RELEASE=${{ matrix.release }}",
+ fmt.Sprintf("PROJECT=%s", project),
+ "PROJECT_REF=${{ env.PROJECT_REF }}",
+ fmt.Sprintf("PROFILES=%s", profiles),
+ fmt.Sprintf("DIST_PACKAGES=%s", distPackages),
+ fmt.Sprintf("PIP_PACKAGES=%s", pipPackages),
+ }
+
+ return &GithubWorkflow{
+ Name: "build",
+ On: GithubWorkflowTrigger{
+ PullRequest: GithubWorkflowPullRequest{},
+ Push: GithubWorkflowPush{
+ Branches: []string{"main"},
+ },
+ },
+ Jobs: map[string]GithubWorkflowJob{
+ "image": {
+ RunsOn: "ubuntu-latest",
+ Strategy: GithubWorkflowStrategy{
+ Matrix: map[string][]string{
+ "release": {"wallaby", "xena", "yoga"},
+ },
+ },
+ Steps: []GithubWorkflowStep{
+ {
+ Name: "Install QEMU static binaries",
+ Uses: "docker/setup-qemu-action@v2",
+ },
+ {
+ Name: "Configure Buildkit",
+ Uses: "docker/setup-buildx-action@v2",
+ },
+ {
+ Name: "Checkout project",
+ Uses: "actions/checkout@v3",
+ },
+ {
+ Name: "Setup environment variables",
+ Run: "echo PROJECT_REF=$(cat manifest.yml | yq \".${{ matrix.release }}.sha\") >> $GITHUB_ENV",
+ },
+ {
+ Name: "Authenticate with Quay.io",
+ Uses: "docker/login-action@v2",
+ With: map[string]string{
+ "registry": "quay.io",
+ "username": "${{ secrets.QUAY_USERNAME }}",
+ "password": "${{ secrets.QUAY_ROBOT_TOKEN }}",
+ },
+ },
+ {
+ Name: "Build image",
+ Uses: "docker/build-push-action@v3",
+ With: map[string]string{
+ "context": ".",
+ "cache-from": "type=gha,scope=${{ matrix.release }}",
+ "cache-to": "type=gha,mode=max,scope=${{ matrix.release }}",
+ "platforms": platforms,
+ "push": "true",
+ "build-args": strings.Join(buildArgs, "\n"),
+ "tags": fmt.Sprintf("quay.io/vexxhost/%s:${{ env.PROJECT_REF }}", project),
+ },
+ },
+ {
+ Name: "Promote image",
+ Uses: "akhilerm/tag-push-action@v2.0.0",
+ If: "github.ref == 'refs/heads/main'",
+ With: map[string]string{
+ "src": fmt.Sprintf("quay.io/vexxhost/%s:${{ env.PROJECT_REF }}", project),
+ "dst": fmt.Sprintf("quay.io/vexxhost/%s:${{ matrix.release }}", project),
+ },
+ },
+ },
+ },
+ },
+ }
+}
diff --git a/internal/pkg/image_repositories/dependabot.go b/internal/pkg/image_repositories/dependabot.go
new file mode 100644
index 0000000..b430146
--- /dev/null
+++ b/internal/pkg/image_repositories/dependabot.go
@@ -0,0 +1,50 @@
+package image_repositories
+
+import (
+ "io"
+
+ "github.com/go-git/go-billy/v5"
+ "github.com/goccy/go-yaml"
+)
+
+type DependabotConfig struct {
+ Version int `yaml:"version"`
+ Updates []DependabotUpdate `yaml:"updates"`
+}
+
+type DependabotUpdate struct {
+ PackageEcosystem string `yaml:"package-ecosystem"`
+ Directory string `yaml:"directory"`
+ Schedule DependabotSchedule `yaml:"schedule"`
+}
+
+type DependabotSchedule struct {
+ Interval string `yaml:"interval"`
+}
+
+func NewDependabotConfig() *DependabotConfig {
+ return &DependabotConfig{
+ Version: 2,
+ Updates: []DependabotUpdate{},
+ }
+}
+
+func (d *DependabotConfig) Write(wr io.Writer) error {
+ bytes, err := yaml.Marshal(d)
+ if err != nil {
+ return err
+ }
+
+ _, err = wr.Write(bytes)
+ return err
+}
+
+func (d *DependabotConfig) WriteFile(fs billy.Filesystem) error {
+ f, err := fs.Create(".github/dependabot.yml")
+ if err != nil {
+ return err
+ }
+ defer f.Close()
+
+ return d.Write(f)
+}
diff --git a/internal/pkg/image_repositories/dockerfile.go b/internal/pkg/image_repositories/dockerfile.go
new file mode 100644
index 0000000..9f89286
--- /dev/null
+++ b/internal/pkg/image_repositories/dockerfile.go
@@ -0,0 +1,55 @@
+package image_repositories
+
+import (
+ _ "embed"
+ "io"
+ "text/template"
+
+ "github.com/go-git/go-billy/v5"
+)
+
+//go:embed template/Dockerfile
+var dockerfileTemplate string
+
+type Dockerfile struct {
+ BindepImage string
+ BindepImageTag string
+ BuilderImage string
+ BuilderImageTag string
+ RuntimeImage string
+ RuntimeImageTag string
+
+ template *template.Template
+}
+
+func NewDockerfile() (*Dockerfile, error) {
+ tmpl, err := template.New("Dockerfile").Parse(dockerfileTemplate)
+ if err != nil {
+ return nil, err
+ }
+
+ return &Dockerfile{
+ BindepImage: "quay.io/vexxhost/bindep-loci",
+ BindepImageTag: "latest",
+ BuilderImage: "quay.io/vexxhost/openstack-builder-focal",
+ BuilderImageTag: "latest",
+ RuntimeImage: "quay.io/vexxhost/openstack-runtime-focal",
+ RuntimeImageTag: "latest",
+
+ template: tmpl,
+ }, nil
+}
+
+func (d *Dockerfile) Write(wr io.Writer) error {
+ return d.template.Execute(wr, d)
+}
+
+func (d *Dockerfile) WriteFile(fs billy.Filesystem) error {
+ f, err := fs.Create("Dockerfile")
+ if err != nil {
+ return err
+ }
+ defer f.Close()
+
+ return d.Write(f)
+}
diff --git a/internal/pkg/image_repositories/dockerignore.go b/internal/pkg/image_repositories/dockerignore.go
new file mode 100644
index 0000000..bc81f36
--- /dev/null
+++ b/internal/pkg/image_repositories/dockerignore.go
@@ -0,0 +1,29 @@
+package image_repositories
+
+import (
+ "io"
+
+ "github.com/go-git/go-billy/v5"
+)
+
+type DockerIgnore struct {
+}
+
+func NewDockerIgnore() *DockerIgnore {
+ return &DockerIgnore{}
+}
+
+func (d *DockerIgnore) Write(wr io.Writer) error {
+ _, err := wr.Write([]byte("*\n"))
+ return err
+}
+
+func (d *DockerIgnore) WriteFile(fs billy.Filesystem) error {
+ f, err := fs.Create(".dockerignore")
+ if err != nil {
+ return err
+ }
+ defer f.Close()
+
+ return d.Write(f)
+}
diff --git a/internal/pkg/image_repositories/github_workflow.go b/internal/pkg/image_repositories/github_workflow.go
new file mode 100644
index 0000000..06e523a
--- /dev/null
+++ b/internal/pkg/image_repositories/github_workflow.go
@@ -0,0 +1,64 @@
+package image_repositories
+
+import (
+ "io"
+
+ "github.com/go-git/go-billy/v5"
+ "github.com/goccy/go-yaml"
+)
+
+type GithubWorkflow struct {
+ Name string `yaml:"name"`
+ On GithubWorkflowTrigger `yaml:"on"`
+ Jobs map[string]GithubWorkflowJob `yaml:"jobs"`
+}
+
+type GithubWorkflowTrigger struct {
+ PullRequest GithubWorkflowPullRequest `yaml:"pull_request"`
+ Push GithubWorkflowPush `yaml:"push"`
+}
+
+type GithubWorkflowPullRequest struct {
+}
+
+type GithubWorkflowPush struct {
+ Branches []string `yaml:"branches"`
+}
+
+type GithubWorkflowJob struct {
+ RunsOn string `yaml:"runs-on"`
+ Strategy GithubWorkflowStrategy `yaml:"strategy"`
+ Steps []GithubWorkflowStep `yaml:"steps"`
+}
+
+type GithubWorkflowStrategy struct {
+ Matrix map[string][]string `yaml:"matrix"`
+}
+
+type GithubWorkflowStep struct {
+ Name string `yaml:"name"`
+ Run string `yaml:"run,omitempty"`
+ Uses string `yaml:"uses,omitempty"`
+ If string `yaml:"if,omitempty"`
+ With map[string]string `yaml:"with,omitempty"`
+}
+
+func (g *GithubWorkflow) Write(wr io.Writer) error {
+ bytes, err := yaml.Marshal(g)
+ if err != nil {
+ return err
+ }
+
+ _, err = wr.Write(bytes)
+ return err
+}
+
+func (g *GithubWorkflow) WriteFile(fs billy.Filesystem) error {
+ f, err := fs.Create(".github/workflows/build.yml")
+ if err != nil {
+ return err
+ }
+ defer f.Close()
+
+ return g.Write(f)
+}
diff --git a/internal/pkg/image_repositories/image_repository.go b/internal/pkg/image_repositories/image_repository.go
new file mode 100644
index 0000000..bcb9f7a
--- /dev/null
+++ b/internal/pkg/image_repositories/image_repository.go
@@ -0,0 +1,295 @@
+package image_repositories
+
+import (
+ "context"
+ "fmt"
+ "net/http"
+ "os"
+
+ "github.com/go-git/go-billy/v5"
+ "github.com/go-git/go-billy/v5/memfs"
+ "github.com/go-git/go-git/v5"
+ "github.com/go-git/go-git/v5/config"
+ "github.com/go-git/go-git/v5/plumbing"
+ git_http "github.com/go-git/go-git/v5/plumbing/transport/http"
+ "github.com/go-git/go-git/v5/storage/memory"
+ "github.com/google/go-github/v47/github"
+ log "github.com/sirupsen/logrus"
+ "golang.org/x/oauth2"
+)
+
+type ImageRepository struct {
+ Project string
+
+ githubClient *github.Client
+ gitAuth *git_http.BasicAuth
+}
+
+func NewImageRepository(project string) *ImageRepository {
+ githubToken := os.Getenv("GITHUB_TOKEN")
+
+ ctx := context.TODO()
+ ts := oauth2.StaticTokenSource(
+ &oauth2.Token{AccessToken: os.Getenv("GITHUB_TOKEN")},
+ )
+ tc := oauth2.NewClient(ctx, ts)
+
+ return &ImageRepository{
+ Project: project,
+
+ githubClient: github.NewClient(tc),
+ gitAuth: &git_http.BasicAuth{
+ Username: githubToken,
+ },
+ }
+}
+
+func (i *ImageRepository) WriteFiles(fs billy.Filesystem) error {
+ // .github/workflows/build.yml
+ build := NewBuildWorkflow(i.Project)
+ err := build.WriteFile(fs)
+ if err != nil {
+ return err
+ }
+
+ // .github/workflows/sync.yml
+
+ // .github/dependabot.yml
+ dab := NewDependabotConfig()
+ err = dab.WriteFile(fs)
+ if err != nil {
+ return err
+ }
+
+ // .dockerignore
+ di := NewDockerIgnore()
+ err = di.WriteFile(fs)
+ if err != nil {
+ return err
+ }
+
+ // .pre-commit-config.yaml
+ pcc := NewPreCommitConfig()
+ err = pcc.WriteFile(fs)
+ if err != nil {
+ return err
+ }
+
+ // Dockerfile
+ df, err := NewDockerfile()
+ if err != nil {
+ return err
+ }
+ err = df.WriteFile(fs)
+ if err != nil {
+ return err
+ }
+
+ // manifest.yml
+ mf, err := NewImageManifest(i.Project)
+ if err != nil {
+ return err
+ }
+ err = mf.WriteFile(fs)
+ if err != nil {
+ return err
+ }
+
+ // README.md
+ rm, err := NewReadme(i.Project)
+ if err != nil {
+ return err
+ }
+ err = rm.WriteFile(fs)
+ if err != nil {
+ return err
+ }
+
+ return nil
+}
+
+func (i *ImageRepository) CreateOrGet(ctx context.Context) (*github.Repository, error) {
+ projectName := fmt.Sprintf("docker-openstack-%s", i.Project)
+
+ _, resp, err := i.githubClient.Repositories.Get(ctx, "vexxhost", projectName)
+ if err != nil && resp.StatusCode == http.StatusNotFound {
+ _, _, err = i.githubClient.Repositories.Create(ctx, "vexxhost", &github.Repository{
+ Name: github.String(projectName),
+ })
+ if err != nil {
+ return nil, err
+ }
+ }
+
+ // Description
+ description := fmt.Sprintf("Docker image for OpenStack: %s", i.Project)
+
+ // Updated repository
+ repo := &github.Repository{
+ AllowMergeCommit: github.Bool(false),
+ AllowRebaseMerge: github.Bool(true),
+ AllowSquashMerge: github.Bool(false),
+ DeleteBranchOnMerge: github.Bool(true),
+ Description: github.String(description),
+ Visibility: github.String("public"),
+ HasWiki: github.Bool(false),
+ HasIssues: github.Bool(false),
+ HasProjects: github.Bool(false),
+ }
+
+ // Update the repository with the correct settings
+ repo, _, err = i.githubClient.Repositories.Edit(ctx, "vexxhost", projectName, repo)
+ if err != nil {
+ return nil, err
+ }
+
+ // Branch protection
+ protection := &github.ProtectionRequest{
+ RequiredPullRequestReviews: &github.PullRequestReviewsEnforcementRequest{
+ RequiredApprovingReviewCount: 1,
+ DismissStaleReviews: true,
+ BypassPullRequestAllowancesRequest: &github.BypassPullRequestAllowancesRequest{
+ Users: []string{"mnaser"},
+ Teams: []string{},
+ Apps: []string{},
+ },
+ },
+ RequiredStatusChecks: &github.RequiredStatusChecks{
+ Strict: true,
+ Contexts: nil,
+ Checks: []*github.RequiredStatusCheck{
+ {
+ Context: "image (wallaby)",
+ },
+ {
+ Context: "image (xena)",
+ },
+ {
+ Context: "image (yoga)",
+ },
+ },
+ },
+ RequiredConversationResolution: github.Bool(true),
+ RequireLinearHistory: github.Bool(true),
+ EnforceAdmins: true,
+ AllowForcePushes: github.Bool(false),
+ AllowDeletions: github.Bool(false),
+ }
+ _, _, err = i.githubClient.Repositories.UpdateBranchProtection(ctx, *repo.Owner.Login, *repo.Name, "main", protection)
+ if err != nil {
+ return nil, err
+ }
+
+ return repo, err
+}
+
+func (i *ImageRepository) Synchronize(ctx context.Context) error {
+ githubRepo, err := i.CreateOrGet(ctx)
+ if err != nil {
+ return err
+ }
+
+ storer := memory.NewStorage()
+ fs := memfs.New()
+
+ repo, err := git.Clone(storer, fs, &git.CloneOptions{
+ Auth: i.gitAuth,
+ URL: *githubRepo.SSHURL,
+ })
+ if err != nil {
+ return err
+ }
+
+ headRef, err := repo.Head()
+ if err != nil {
+ return err
+ }
+
+ ref := plumbing.NewHashReference("refs/heads/sync/atmosphere-ci", headRef.Hash())
+ err = repo.Storer.SetReference(ref)
+ if err != nil {
+ return err
+ }
+
+ worktree, err := repo.Worktree()
+ if err != nil {
+ return err
+ }
+
+ err = worktree.Checkout(&git.CheckoutOptions{
+ Branch: ref.Name(),
+ })
+ if err != nil {
+ return err
+ }
+
+ err = i.WriteFiles(fs)
+ if err != nil {
+ return err
+ }
+
+ status, err := worktree.Status()
+ if err != nil {
+ return err
+ }
+
+ if status.IsClean() {
+ log.Info("No changes to commit")
+ return nil
+ }
+
+ _, err = worktree.Add(".")
+ if err != nil {
+ return err
+ }
+
+ commit, err := worktree.Commit("chore: sync using `atmosphere-ci`", &git.CommitOptions{
+ All: true,
+ })
+ if err != nil {
+ return err
+ }
+
+ err = repo.Push(&git.PushOptions{
+ Auth: i.gitAuth,
+ RefSpecs: []config.RefSpec{"refs/heads/sync/atmosphere-ci:refs/heads/sync/atmosphere-ci"},
+ Force: true,
+ })
+ if err != nil {
+ return err
+ }
+
+ err = i.CreatePullRequest(ctx, githubRepo, commit)
+ if err != nil {
+ return err
+ }
+
+ return nil
+}
+
+func (i *ImageRepository) CreatePullRequest(ctx context.Context, repo *github.Repository, commit plumbing.Hash) error {
+ newPR := &github.NewPullRequest{
+ Title: github.String("⚙️ Automatic sync from `atmosphere-ci`"),
+ Head: github.String("sync/atmosphere-ci"),
+ Base: github.String("main"),
+ Body: github.String("This is an automatic pull request from `atmosphere-ci`"),
+ }
+
+ prs, _, err := i.githubClient.PullRequests.ListPullRequestsWithCommit(ctx, *repo.Owner.Login, *repo.Name, commit.String(), &github.PullRequestListOptions{})
+ if err != nil {
+ return err
+ }
+
+ if len(prs) > 0 {
+ log.Info("Pull request already exists: ", prs[0].GetHTMLURL())
+ return nil
+ }
+
+ pr, resp, err := i.githubClient.PullRequests.Create(ctx, *repo.Owner.Login, *repo.Name, newPR)
+ if err != nil && resp.StatusCode != http.StatusUnprocessableEntity {
+ return err
+ }
+
+ log.Info("PR created: ", pr.GetHTMLURL())
+ return nil
+}
diff --git a/internal/pkg/image_repositories/manifest.go b/internal/pkg/image_repositories/manifest.go
new file mode 100644
index 0000000..d27bbe0
--- /dev/null
+++ b/internal/pkg/image_repositories/manifest.go
@@ -0,0 +1,81 @@
+package image_repositories
+
+import (
+ "fmt"
+ "io"
+
+ "code.gitea.io/sdk/gitea"
+ "github.com/go-git/go-billy/v5"
+ "github.com/goccy/go-yaml"
+)
+
+type ReleaseManifest struct {
+ SHA string `json:"sha"`
+}
+
+type ImageManifest struct {
+ Wallaby *ReleaseManifest `yaml:"wallaby"`
+ Xena *ReleaseManifest `yaml:"xena"`
+ Yoga *ReleaseManifest `yaml:"yoga"`
+}
+
+func NewImageManifest(project string) (*ImageManifest, error) {
+ client, err := gitea.NewClient("https://opendev.org")
+ if err != nil {
+ return nil, err
+ }
+
+ wallaby, err := getReleaseManifest(client, project, "wallaby")
+ if err != nil {
+ return nil, err
+ }
+
+ xena, err := getReleaseManifest(client, project, "xena")
+ if err != nil {
+ return nil, err
+ }
+
+ yoga, err := getReleaseManifest(client, project, "yoga")
+ if err != nil {
+ return nil, err
+ }
+
+ return &ImageManifest{
+ Wallaby: wallaby,
+ Xena: xena,
+ Yoga: yoga,
+ }, nil
+}
+
+func (m *ImageManifest) Write(wr io.Writer) error {
+ bytes, err := yaml.Marshal(m)
+ if err != nil {
+ return err
+ }
+
+ _, err = wr.Write(bytes)
+ return err
+}
+
+func (m *ImageManifest) WriteFile(fs billy.Filesystem) error {
+ f, err := fs.Create("manifest.yml")
+ if err != nil {
+ return err
+ }
+ defer f.Close()
+
+ return m.Write(f)
+}
+
+func getReleaseManifest(client *gitea.Client, project, release string) (*ReleaseManifest, error) {
+ branchName := fmt.Sprintf("stable/%s", release)
+
+ branch, _, err := client.GetRepoBranch("openstack", project, branchName)
+ if err != nil {
+ return nil, err
+ }
+
+ return &ReleaseManifest{
+ SHA: branch.Commit.ID,
+ }, nil
+}
diff --git a/internal/pkg/image_repositories/pre_commit_config.go b/internal/pkg/image_repositories/pre_commit_config.go
new file mode 100644
index 0000000..7c98576
--- /dev/null
+++ b/internal/pkg/image_repositories/pre_commit_config.go
@@ -0,0 +1,60 @@
+package image_repositories
+
+import (
+ "io"
+
+ "github.com/go-git/go-billy/v5"
+ "github.com/goccy/go-yaml"
+)
+
+type PreCommitConfig struct {
+ Repositories []PreCommitRepository `yaml:"repos"`
+}
+
+type PreCommitRepository struct {
+ Repository string `yaml:"repo"`
+ Revision string `yaml:"rev"`
+ Hooks []PreCommitHook `yaml:"hooks"`
+}
+
+type PreCommitHook struct {
+ ID string `yaml:"id"`
+ Stages []string `yaml:"stages"`
+}
+
+func NewPreCommitConfig() *PreCommitConfig {
+ return &PreCommitConfig{
+ Repositories: []PreCommitRepository{
+ {
+ Repository: "https://github.com/compilerla/conventional-pre-commit",
+ Revision: "v2.0.0",
+ Hooks: []PreCommitHook{
+ {
+ ID: "conventional-pre-commit",
+ Stages: []string{"commit-msg"},
+ },
+ },
+ },
+ },
+ }
+}
+
+func (c *PreCommitConfig) Write(wr io.Writer) error {
+ bytes, err := yaml.Marshal(c)
+ if err != nil {
+ return err
+ }
+
+ _, err = wr.Write(bytes)
+ return err
+}
+
+func (c *PreCommitConfig) WriteFile(fs billy.Filesystem) error {
+ f, err := fs.Create(".pre-commit-config.yaml")
+ if err != nil {
+ return err
+ }
+ defer f.Close()
+
+ return c.Write(f)
+}
diff --git a/internal/pkg/image_repositories/readme.go b/internal/pkg/image_repositories/readme.go
new file mode 100644
index 0000000..8bd3890
--- /dev/null
+++ b/internal/pkg/image_repositories/readme.go
@@ -0,0 +1,45 @@
+package image_repositories
+
+import (
+ _ "embed"
+ "io"
+ "text/template"
+
+ "github.com/go-git/go-billy/v5"
+)
+
+//go:embed template/README.md
+var readmeTemplate string
+
+type Readme struct {
+ Project string
+
+ template *template.Template
+}
+
+func NewReadme(project string) (*Readme, error) {
+ tmpl, err := template.New("README.md").Parse(readmeTemplate)
+ if err != nil {
+ return nil, err
+ }
+
+ return &Readme{
+ Project: project,
+
+ template: tmpl,
+ }, nil
+}
+
+func (r *Readme) Write(wr io.Writer) error {
+ return r.template.Execute(wr, r)
+}
+
+func (r *Readme) WriteFile(fs billy.Filesystem) error {
+ f, err := fs.Create("README.md")
+ if err != nil {
+ return err
+ }
+ defer f.Close()
+
+ return r.Write(f)
+}
diff --git a/internal/pkg/image_repositories/template/Dockerfile b/internal/pkg/image_repositories/template/Dockerfile
new file mode 100644
index 0000000..95d0f0f
--- /dev/null
+++ b/internal/pkg/image_repositories/template/Dockerfile
@@ -0,0 +1,10 @@
+# syntax=docker/dockerfile:1.4
+
+FROM {{ .BindepImage }}:{{ .BindepImageTag }} AS bindep
+
+FROM {{ .BuilderImage }}:{{ .BuilderImageTag }} AS builder
+COPY --from=bindep --link /runtime-pip-packages /runtime-pip-packages
+
+FROM {{ .RuntimeImage }}:{{ .RuntimeImageTag }} AS runtime
+COPY --from=bindep --link /runtime-dist-packages /runtime-dist-packages
+COPY --from=builder --link /var/lib/openstack /var/lib/openstack
diff --git a/internal/pkg/image_repositories/template/README.md b/internal/pkg/image_repositories/template/README.md
new file mode 100644
index 0000000..81229c1
--- /dev/null
+++ b/internal/pkg/image_repositories/template/README.md
@@ -0,0 +1,9 @@
+# OpenStack Image for `{{ .Project }}`
+
+This is an automatically generated and synchronzied repository for the `{{ .Project }}`
+project images. The repository is built using the `atmosphere-ci` tool that
+lives inside of the [Atmosphere](https://github.com/vexxhost/atmosphere) project.
+
+If you need to make any changes or files issues, please propose them to the
+[Atmosphere](https://github.com/vexxhost/atmosphere) repository or else they
+will be wiped out the next time the repository is synchronized.