upgrade flake + wip alba static push

This commit is contained in:
Quentin 2023-04-20 12:27:14 +02:00
parent 5f8c80ce21
commit cde5c6ad29
Signed by: quentin
GPG key ID: E9602264D639FF68
4 changed files with 2858 additions and 40 deletions

View file

@ -1,26 +1,127 @@
package cmd package cmd
import ( import (
"context"
"errors"
"fmt" "fmt"
"os"
"path/filepath"
"strings"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"gocloud.dev/blob"
_ "gocloud.dev/blob/s3blob"
) )
type Platform struct {
OS string
Arch string
Root string
Files []string
}
func CollectPlatforms(path string) ([]Platform, error) {
var p []Platform
osDirList, err := os.ReadDir(path)
if err != nil {
return p, err
}
// Collect platforms
for _, osDir := range osDirList {
archDirList, err := os.ReadDir(filepath.Join(path, osDir.Name()))
if err != nil {
return p, err
}
for _, archDir := range archDirList {
root := filepath.Join(path, osDir.Name(), archDir.Name())
files, err := os.ReadDir(root)
var filenames []string
for _, f := range files {
filenames = append(filenames, f.Name())
}
if err != nil {
return p, err
}
plat := Platform {
OS: osDir.Name(),
Arch: archDir.Name(),
Root: root,
Files: filenames,
}
p = append(p, plat)
}
}
return p, nil
}
type Artifact struct {
Name string
Tag string
Platforms []Platform
}
func NewArtifact(nametag, path string) (Artifact, error) {
ntspl := strings.Split(nametag, ":")
if len(ntspl) != 2 {
return Artifact{}, errors.New("nametag must be of the form 'name:tag'")
}
ar := Artifact{
Name: ntspl[0],
Tag: ntspl[1],
}
plat, err := CollectPlatforms(path)
if err != nil {
return ar, err
}
ar.Platforms = plat
return ar, nil
}
var staticCmd = &cobra.Command{ var staticCmd = &cobra.Command{
Use: "static", Use: "static",
Short: "Manage static artifacts", Short: "Manage static artifacts",
Long: "There are many ways to ship software, one is simply to publish a bunch of files on a mirror.", Long: "There are many ways to ship software, one is simply to publish a bunch of files on a mirror.",
} }
var tag string
var publishCmd = &cobra.Command{ var publishCmd = &cobra.Command{
Use: "publish", Use: "publish [folder] [remote]", // https://gocloud.dev/howto/blob/#s3-compatible
Short: "Publish a static artifact", Short: "Publish a static artifact",
Long: "Sending logic for a static artifact", Long: "Sending logic for a static artifact",
Args: cobra.ExactArgs(2),
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
fmt.Println("Hugo Static Site Generator v0.9 -- HEAD") localFolder := args[0]
remoteUrl := args[1]
art, err := NewArtifact(tag, localFolder)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
fmt.Printf("%#v\n", art)
bucket, err := blob.OpenBucket(context.Background(), remoteUrl)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
defer bucket.Close()
}, },
} }
func init() { func init() {
publishCmd.Flags().StringVarP(&tag, "tag", "t", "", "Tag of the project, eg. albatros:0.9")
publishCmd.MarkFlagRequired("tag")
staticCmd.AddCommand(publishCmd) staticCmd.AddCommand(publishCmd)
RootCmd.AddCommand(staticCmd) RootCmd.AddCommand(staticCmd)
} }

View file

@ -15,13 +15,21 @@
}; };
# declare the go module of this package, allow for cross compilation # declare the go module of this package, allow for cross compilation
gopkg = arch: (pkgs.buildGoModule rec { albatrosStaticBin = arch: (pkgs.buildGoModule rec {
pname = "albatros-go-module"; pname = "albatros-go-module";
version = "0.9"; version = "0.9";
src = ./.; src = ./.;
CGO_ENABLED = 0; CGO_ENABLED = 0;
vendorSha256 = "sha256-Q7gImRoJqtcORpHLQoF3TRK2WJu3tKSjSE3Sno6lNNk="; vendorSha256 = "sha256-jzRYYsopJDYsar0nSYkTAOCGf4z20sgpDQ/eFmwYzM8=";
checkPhase = "true"; checkPhase = ''
true
'';
buildPhase = ''
go build bin/albatros.go
'';
installPhase = ''
cp albatros $out
'';
meta = with pkgs.lib; { meta = with pkgs.lib; {
description = "albatros is a CI for Nomad"; description = "albatros is a CI for Nomad";
homepage = "https://git.deuxfleurs.fr/quentin/albatros"; homepage = "https://git.deuxfleurs.fr/quentin/albatros";
@ -30,16 +38,6 @@
}; };
}).overrideAttrs (old: old // { GOOS = "linux"; GOARCH = arch; }); }).overrideAttrs (old: old // { GOOS = "linux"; GOARCH = arch; });
# logic to build static binaries
albatrosStaticBin = arch: pkgs.stdenv.mkDerivation {
pname = "albatros";
version = "0.9";
unpackPhase = "true";
installPhase = ''
cp `find ${gopkg arch}/bin -name albatros` $out
'';
};
# logic to build docker containers # logic to build docker containers
docker = staticBin: arch: pkgs.dockerTools.buildImage { docker = staticBin: arch: pkgs.dockerTools.buildImage {
name = "dxflrs/albatros"; name = "dxflrs/albatros";

54
go.mod
View file

@ -8,28 +8,62 @@ require (
github.com/hashicorp/consul/api v1.20.0 github.com/hashicorp/consul/api v1.20.0
github.com/hashicorp/nomad/api v0.0.0-20230314144600-1a01e8719272 github.com/hashicorp/nomad/api v0.0.0-20230314144600-1a01e8719272
github.com/spf13/cobra v1.7.0 github.com/spf13/cobra v1.7.0
golang.org/x/exp v0.0.0-20230108222341-4b8118a2686a gocloud.dev v0.29.0
golang.org/x/exp v0.0.0-20230124195608-d38c7dcee874
) )
require ( require (
github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da // indirect github.com/armon/go-metrics v0.3.10 // indirect
github.com/fatih/color v1.9.0 // indirect github.com/aws/aws-sdk-go v1.44.200 // indirect
github.com/aws/aws-sdk-go-v2 v1.17.4 // indirect
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.4.10 // indirect
github.com/aws/aws-sdk-go-v2/config v1.18.12 // indirect
github.com/aws/aws-sdk-go-v2/credentials v1.13.12 // indirect
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.12.22 // indirect
github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.11.51 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.28 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.22 // indirect
github.com/aws/aws-sdk-go-v2/internal/ini v1.3.29 // indirect
github.com/aws/aws-sdk-go-v2/internal/v4a v1.0.19 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.9.11 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.1.23 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.22 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.13.22 // indirect
github.com/aws/aws-sdk-go-v2/service/s3 v1.30.2 // indirect
github.com/aws/aws-sdk-go-v2/service/sso v1.12.1 // indirect
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.14.1 // indirect
github.com/aws/aws-sdk-go-v2/service/sts v1.18.3 // indirect
github.com/aws/smithy-go v1.13.5 // indirect
github.com/fatih/color v1.13.0 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/wire v0.5.0 // indirect
github.com/googleapis/gax-go/v2 v2.7.0 // indirect
github.com/gorilla/websocket v1.5.0 // indirect github.com/gorilla/websocket v1.5.0 // indirect
github.com/hashicorp/cronexpr v1.1.1 // indirect github.com/hashicorp/cronexpr v1.1.1 // indirect
github.com/hashicorp/errwrap v1.0.0 // indirect github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/go-hclog v0.12.0 // indirect github.com/hashicorp/go-hclog v1.2.0 // indirect
github.com/hashicorp/go-immutable-radix v1.0.0 // indirect github.com/hashicorp/go-immutable-radix v1.3.1 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/go-rootcerts v1.0.2 // indirect github.com/hashicorp/go-rootcerts v1.0.2 // indirect
github.com/hashicorp/go-version v1.2.1 // indirect github.com/hashicorp/go-version v1.2.1 // indirect
github.com/hashicorp/golang-lru v0.5.4 // indirect github.com/hashicorp/golang-lru v0.6.0 // indirect
github.com/hashicorp/serf v0.10.1 // indirect github.com/hashicorp/serf v0.10.1 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/mattn/go-colorable v0.1.6 // indirect github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/mattn/go-isatty v0.0.12 // indirect github.com/mattn/go-colorable v0.1.12 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect github.com/spf13/pflag v1.0.5 // indirect
golang.org/x/sys v0.1.0 // indirect go.opencensus.io v0.24.0 // indirect
golang.org/x/net v0.6.0 // indirect
golang.org/x/sys v0.5.0 // indirect
golang.org/x/text v0.7.0 // indirect
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
google.golang.org/api v0.110.0 // indirect
google.golang.org/genproto v0.0.0-20230209215440-0dfe4f8abfcc // indirect
google.golang.org/grpc v1.53.0 // indirect
google.golang.org/protobuf v1.28.1 // indirect
) )

2715
go.sum

File diff suppressed because it is too large Load diff