This commit is contained in:
Quentin 2023-05-03 10:52:34 +02:00
parent f2e3de4b5d
commit 40fd4646ce
Signed by: quentin
GPG key ID: E9602264D639FF68
9 changed files with 187 additions and 189 deletions

View file

@ -2,8 +2,8 @@ package main
import (
"fmt"
"os"
"git.deuxfleurs.fr/deuxfleurs/albatros/cmd"
"os"
)
func main() {

View file

@ -1,10 +1,10 @@
package cmd
import (
"crypto/sha256"
"errors"
"context"
"crypto/sha256"
"encoding/json"
"errors"
"fmt"
"io"
"os"
@ -13,17 +13,17 @@ import (
"strconv"
"strings"
"github.com/containers/image/v5/transports/alltransports"
"github.com/containers/image/v5/signature"
"github.com/containers/image/v5/copy"
"github.com/containers/image/v5/signature"
"github.com/containers/image/v5/transports/alltransports"
"github.com/spf13/cobra"
"gocloud.dev/blob"
_ "gocloud.dev/blob/s3blob"
)
var pctx *signature.PolicyContext
const distributionPrefix = "v2"
const distributionPrefix = "v2"
//---
//--- Image converter
@ -33,6 +33,7 @@ type OCIImageManifest struct {
Config OCIRef `json:"config"`
Layers []OCIRef `json:layers"`
}
func LoadOCIImageManifest(path string) (*OCIImageManifest, error) {
fd, err := os.Open(path)
if err != nil {
@ -71,8 +72,9 @@ type OCIImageIndex struct {
MediaType string `json:"mediaType"`
Manifests []OCIRef `json:"manifests"`
}
func NewOCIImageIndex(o *OCIMultiArch) (OCIImageIndex, error) {
idx := OCIImageIndex {
idx := OCIImageIndex{
SchemaVersion: 2,
MediaType: "application/vnd.oci.image.index.v1+json",
Manifests: []OCIRef{},
@ -130,6 +132,7 @@ func (i OCIImageIndex) WriteTo(root string) error {
type OCILayout struct {
ImageLayoutVersion string `json:"imageLayoutVersion"`
}
func NewOCILayout() OCILayout {
return OCILayout{"1.0.0"}
}
@ -151,8 +154,9 @@ type OCISystemImage struct {
arch string
index *OCIImageIndex
}
func NewOCISystemImage(path, os, arch string) (OCISystemImage, error) {
si := OCISystemImage {
si := OCISystemImage{
path: path,
os: os,
arch: arch,
@ -171,7 +175,7 @@ func NewOCISystemImage(path, os, arch string) (OCISystemImage, error) {
}
// Enrich manifest
si.index.Manifests[0].Platform = &OCIPlatform {
si.index.Manifests[0].Platform = &OCIPlatform{
Architecture: arch,
OS: os,
}
@ -201,7 +205,7 @@ func NewOCIMultiArch(nametag string) (*OCIMultiArch, error) {
return nil, err
}
return &OCIMultiArch {
return &OCIMultiArch{
Name: ntspl[0],
Tag: ntspl[1],
path: tmp,
@ -252,7 +256,6 @@ func (o *OCIMultiArch) LoadFromDockerArchives(path string) error {
return err
}
// Convert the docker archive to an oci image
_, err = copy.Image(context.Background(), pctx, dstRef, srcRef, &copy.Options{})
if err != nil {
@ -288,7 +291,6 @@ func (o *OCIMultiArch) MergeSystemImages() error {
return err
}
// Create the oci-layout file
err = NewOCILayout().WriteTo(multiArchRoot)
if err != nil {
@ -308,7 +310,6 @@ func (o *OCIMultiArch) MergeSystemImages() error {
o.multi = &idx
fmt.Printf("-> index.json\n")
// Copy blobs
for _, img := range o.images {
blobCounter := 0
@ -462,7 +463,6 @@ func (o *OCIMultiArch) UploadImageS3(buck *blob.Bucket) error {
return nil
}
type StaticRegistryManager struct {
name string
buck *blob.Bucket

View file

@ -44,7 +44,6 @@ type Manifest struct {
Tags []string `json:"tags"`
}
//---
//--- Collect data on the filesystem
type Platform struct {
@ -83,8 +82,7 @@ func CollectPlatforms(path string) ([]Platform, error) {
filenames = append(filenames, f.Name())
}
plat := Platform {
plat := Platform{
OS: osDir.Name(),
Arch: archDir.Name(),
Root: root,
@ -98,7 +96,7 @@ func CollectPlatforms(path string) ([]Platform, error) {
}
func (p *Platform) BuildRegistryPlatform() RegistryPlatform {
return RegistryPlatform {
return RegistryPlatform{
Architecture: p.Arch,
OS: p.OS,
}
@ -140,7 +138,7 @@ func NewArtifact(nametag, path string) (Artifact, error) {
}
func (a *Artifact) UpdateManifest() Manifest {
return Manifest {
return Manifest{
Name: a.Name,
Tags: []string{a.Tag}, //@FIXME we must fetch the other tags of the repo
}
@ -149,7 +147,7 @@ func (a *Artifact) UpdateManifest() Manifest {
func (a *Artifact) BuildTag() Tag {
t := Tag{Flavors: []Flavor{}}
for _, p := range a.Platforms {
f := Flavor {
f := Flavor{
Resources: p.BuildResources(),
Platform: p.BuildRegistryPlatform(),
}
@ -212,6 +210,7 @@ type BucketUploader struct {
reader io.ReadCloser
options *blob.WriterOptions
}
func NewUploadFromFS(buck *blob.Bucket, path string) (*BucketUploader, error) {
fd, err := os.Open(path)
if err != nil {

View file

@ -1,18 +1,17 @@
package pkg
import (
"log"
consul "github.com/hashicorp/consul/api"
nomad "github.com/hashicorp/nomad/api"
"log"
)
type Cluster struct {
Nomad *nomad.Client
Consul *consul.Client
}
func NewCluster(conf* Config) Cluster {
func NewCluster(conf *Config) Cluster {
cluster := Cluster{}
// Init Nomad

View file

@ -1,9 +1,9 @@
package pkg
import (
"log"
"fmt"
"github.com/caarlos0/env/v7"
"log"
)
type Config struct {

View file

@ -4,10 +4,10 @@ import (
b64 "encoding/base64"
"encoding/json"
"fmt"
"golang.org/x/exp/slices"
"io"
"log"
"net/http"
"golang.org/x/exp/slices"
"strings"
nomad "github.com/hashicorp/nomad/api"
@ -101,7 +101,7 @@ func (h HookHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
log.Printf("Created job %s for %s\n", dres.DispatchedJobID, notifInfo)
// Start a lifecycle observer to update gitea status
j := Job {
j := Job{
Cluster: h.Cluster,
Config: h.Config,
Notification: &notification,

View file

@ -1,9 +1,9 @@
package pkg
import (
"log"
"code.gitea.io/sdk/gitea"
nomad "github.com/hashicorp/nomad/api"
"log"
)
type Job struct {