feat: with updated image
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Kasper Juul Hermansen 2023-04-08 12:11:12 +02:00
parent 7d4f4cc700
commit f46847a523
Signed by: kjuulh
GPG Key ID: 57B6E1465221F912
6 changed files with 129 additions and 5 deletions

View File

@ -8,7 +8,7 @@ steps:
- name: dockersock - name: dockersock
path: /var/run path: /var/run
environment: environment:
#DOCKER_BUILDKIT: 1 DOCKER_BUILDKIT: 1
DOCKER_PASSWORD: DOCKER_PASSWORD:
from_secret: docker_password from_secret: docker_password
DOCKER_USERNAME: DOCKER_USERNAME:

1
.gitignore vendored
View File

@ -1 +1,2 @@
.shuttle/ .shuttle/
.env

91
shuttletask/ci.go Normal file
View File

@ -0,0 +1,91 @@
package main
import (
"context"
"fmt"
"log"
"os"
"path"
"dagger.io/dagger"
"github.com/joho/godotenv"
"golang.org/x/sync/errgroup"
)
func Ci(ctx context.Context) error {
_ = godotenv.Load()
client, err := dagger.Connect(ctx, dagger.WithLogOutput(os.Stdout))
if err != nil {
return err
}
defer client.Close()
drone := client.
Container(dagger.ContainerOpts{Platform: "linux/amd64"}).
From("debian").
WithExec([]string{
"apt", "update",
}).
WithExec([]string{
"apt", "install", "-y", "wget", "tar",
}).
WithExec([]string{
"wget", "https://github.com/harness/drone-cli/releases/latest/download/drone_linux_amd64.tar.gz",
}).
WithExec([]string{
"tar", "-xvf", "drone_linux_amd64.tar.gz",
}).
WithExec([]string{
"mv", "drone", "/usr/local/bin",
}).
WithExec([]string{
"drone", "--version",
})
_, err = drone.ExitCode(ctx)
if err != nil {
return err
}
templates := client.Host().Directory("templates")
droneTemplates := drone.
WithEnvVariable("DRONE_SERVER", "https://ci.i.kjuulh.io").
WithEnvVariable("DRONE_TOKEN", os.Getenv("DRONE_TOKEN")).
WithExec([]string{"drone", "info"}).
WithMountedDirectory("/mnt/templates", templates).
WithWorkdir("/mnt/templates")
entries, err := templates.Entries(ctx)
if err != nil {
return err
}
egrp, _ := errgroup.WithContext(ctx)
for _, entry := range entries {
entry := entry
egrp.Go(func() error {
name := path.Base(entry)
namespace := "kjuulh"
log.Printf("running for: %s", entry)
_, err := droneTemplates.
WithExec([]string{
"drone", "template", "add", "--namespace", namespace, "--name", name, "--data", fmt.Sprintf("@%s", name),
}).
WithExec([]string{
"drone", "template", "update", "--namespace", namespace, "--name", name, "--data", fmt.Sprintf("@%s", name),
}).
ExitCode(ctx)
return err
})
}
if err := egrp.Wait(); err != nil {
return err
}
return nil
}

View File

@ -17,6 +17,7 @@ require (
github.com/davecgh/go-spew v1.1.1 // indirect github.com/davecgh/go-spew v1.1.1 // indirect
github.com/golang/protobuf v1.5.2 // indirect github.com/golang/protobuf v1.5.2 // indirect
github.com/iancoleman/strcase v0.2.0 // indirect github.com/iancoleman/strcase v0.2.0 // indirect
github.com/joho/godotenv v1.5.1 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.1.0-rc2.0.20221005185240-3a7f492d3f1b // indirect github.com/opencontainers/image-spec v1.1.0-rc2.0.20221005185240-3a7f492d3f1b // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect

View File

@ -33,6 +33,8 @@ github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/ad
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
github.com/iancoleman/strcase v0.2.0 h1:05I4QRnGpI0m37iZQRuskXh+w77mr6Z41lwQzuHLwW0= github.com/iancoleman/strcase v0.2.0 h1:05I4QRnGpI0m37iZQRuskXh+w77mr6Z41lwQzuHLwW0=
github.com/iancoleman/strcase v0.2.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47ZCWhYzw7ho= github.com/iancoleman/strcase v0.2.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47ZCWhYzw7ho=
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
github.com/kevinmbeaulieu/eq-go v1.0.0/go.mod h1:G3S8ajA56gKBZm4UB9AOyoOS37JO3roToPzKNM8dtdM= github.com/kevinmbeaulieu/eq-go v1.0.0/go.mod h1:G3S8ajA56gKBZm4UB9AOyoOS37JO3roToPzKNM8dtdM=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= 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 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=

View File

@ -1,16 +1,45 @@
type: docker type: docker
kind: pipeline kind: pipeline
name: "drone-dagger-test" name: "shuttle-drone-templates"
steps: steps:
- name: "build" - name: "wait for dind"
image: docker.io/kjuulh/shuttle-drone image: docker:dind
volumes: volumes:
- name: dockersock - name: dockersock
path: /var/run path: /var/run
environment: environment:
DOCKER_BUILDKIT: 1 DOCKER_BUILDKIT: 1
DOCKER_PASSWORD:
from_secret: docker_password
DOCKER_USERNAME:
from_secret: docker_username
commands: commands:
- sleep 5 - ls /var/run
- set -eu
- sleep 10
- echo "$${DOCKER_PASSWORD}" | docker login --password-stdin --username="$${DOCKER_USERNAME}" "$${DOCKER_HOST}"
- name: "build"
image: docker.io/kasperhermansen/shuttle-drone:1680894029336
volumes:
- name: dockersock
path: /var/run
environment:
DOCKER_BUILDKIT: 1
DOCKER_PASSWORD:
from_secret: docker_password
DOCKER_USERNAME:
from_secret: docker_username
DRONE_TOKEN:
from_secret: drone_token
SSH_KEY:
from_secret: gitea_id_ed25519
commands:
- set -eu
- eval `ssh-agent`
- mkdir -p ~/.ssh
- echo "$SSH_KEY" | base64 -d > ~/.ssh/id_ed25519
- chmod -R 600 ~/.ssh
- ssh-add
- echo "$${DOCKER_PASSWORD}" | docker login --password-stdin --username="$${DOCKER_USERNAME}" "$${DOCKER_HOST}" - echo "$${DOCKER_PASSWORD}" | docker login --password-stdin --username="$${DOCKER_USERNAME}" "$${DOCKER_HOST}"
- shuttle run build - shuttle run build
services: services: