-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
135 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
FROM golang:1.23 AS builder | ||
RUN apt-get update | ||
# do the thing with cache directories from my article, I'll do it later | ||
WORKDIR /app | ||
|
||
COPY main.go main.go | ||
COPY go.mod go.mod | ||
COPY go.sum go.sum | ||
RUN --mount=type=cache,target=/go/pkg/mod/ go mod download | ||
COPY . . | ||
# build our application | ||
RUN --mount=type=cache,target=/root/.cache/go-build GOOS=linux GOARCH=amd64 go build -o runpodctl . | ||
RUN --mount=type=cache,target=/root/.cache/go-build GOOS=linux GOARCH=amd64 go build -o configure-github-action ./cmd/configure-github-action | ||
|
||
FROM ubuntu:latest AS runner | ||
COPY --from=builder /app/runpodctl /app/runpodctl | ||
COPY --from=builder /app/configure-github-action /app/configure-github-action |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
name: "build-dockerfile" | ||
on: [push] | ||
jobs: | ||
docker-build: | ||
runs-on: efrondev/test-runpod-runner | ||
steps: | ||
- name: Set up QEMU | ||
uses: docker/setup-qemu-action@v2 | ||
|
||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v2 | ||
|
||
- name: Login to Docker Hub | ||
uses: docker/login-action@v2 | ||
with: | ||
username: ${{ secrets.DOCKERHUB_USERNAME }} | ||
password: ${{ secrets.DOCKERHUB_TOKEN }} | ||
|
||
- name: checkout | ||
uses: actions/checkout@v4 | ||
|
||
- name: generate-config-if-necessary | ||
run: | | ||
/app/configure-github-action | ||
- name: | ||
|
||
# Build and push step | ||
- name: Build and push | ||
uses: docker/build-push-action@v4 | ||
with: | ||
push: true | ||
tags: ${{ vars.DOCKERHUB_REPO }}/${{ vars.DOCKERHUB_IMG }}:${{ (github.event_name == 'release' && github.event.release.tag_name) || (github.event_name == 'workflow_dispatch' && github.event.inputs.image_tag) || 'dev' }} | ||
|
||
- name: deploy-endpoint | ||
run: | | ||
runpodctl project deploy --mode=dockerfile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// configure-github-action is a small tool that generates a Dockerfile and endpoint.toml file from a runpod.toml file. | ||
// If you already have those two, this is a no-op. | ||
package main | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"fmt" | ||
"log" | ||
"os" | ||
"os/exec" | ||
"path/filepath" | ||
"strings" | ||
) | ||
|
||
type EndpointConfig struct{} | ||
|
||
func main() { | ||
dir := "." | ||
if len(os.Args) > 1 { | ||
dir = os.Args[1] | ||
} | ||
log.SetPrefix("configure-github-action: ") | ||
log.Printf("start: dir=%s", dir) | ||
if err := build(context.TODO(), dir); err != nil { | ||
log.Fatalf("fail: %v", err) | ||
} | ||
log.Printf("done") | ||
} | ||
|
||
// if they have dockerfile+endpoint.toml, use that | ||
// otherwise, use runpod.toml to generate the dockerfile | ||
func build(ctx context.Context, dir string) error { | ||
exists := func(path string) bool { | ||
_, err := os.Stat(filepath.Join(".", path)) | ||
return err == nil | ||
} | ||
// runpodctl commmands only work on current directory, so we chdir | ||
oldDir, _ := os.Getwd() | ||
os.Chdir(dir) | ||
defer os.Chdir(oldDir) | ||
|
||
switch { // bounds checks | ||
case !exists("runpod.toml") && !exists("Dockerfile") && !exists("endpoint.toml"): | ||
return errors.New("no runpod.toml, Dockerfile, or endpoint.toml found... did you choose the right directory?") | ||
case exists("runpod.toml") && (exists("Dockerfile") || exists("endpoint.toml")): | ||
return errors.New("expected no Dockerfile or endpoint.toml when runpod.toml is present") | ||
case exists("runpod.toml"): | ||
log.Print("found runpod.toml") | ||
|
||
for _, cmdAndArgs := range [][]string{ | ||
{"runpodctl", "project", "generate-endpoint-config"}, | ||
{"runpodctl", "project", "build-dockerfile"}, | ||
} { | ||
log.Printf("start %v", strings.Join(cmdAndArgs, " ")) | ||
cmd := exec.CommandContext(ctx, cmdAndArgs[0], cmdAndArgs[1:]...) | ||
cmd.Stdout, cmd.Stderr = os.Stdout, os.Stderr | ||
if err := cmd.Run(); err != nil { | ||
return fmt.Errorf("%v: %v", strings.Join(cmdAndArgs, " "), err) | ||
} | ||
} | ||
log.Printf("generated Dockerfile and endpoint.toml") | ||
return nil | ||
case exists("Dockerfile") && exists("endpoint.toml"): | ||
log.Print("found pre-existing Dockerfile and endpoint.toml") | ||
return nil | ||
default: | ||
return errors.New("expected either 'runpod.toml' or both 'Dockerfile' and 'endpoint.toml' to exist") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters