#Is there any guidance on improving a

1 messages · Page 1 of 1 (latest)

jovial spoke
#

could you please provide more context?

what SDK and type of app are you building? Is it slow in your machine or CI?

gaunt fossil
#

I'm building a Go project using the Go SDK. Contrasting it to the existing build (sub 2 minutes) Dagger is 3+ minutes. Can DM you the different builds. I think a big factor might be the download of dagger itself but it raises the question of "how do I inspect and optimize" a dagger build.

jovial spoke
gaunt fossil
#

I'm using CodeBuild without any caches. Daggerized build looks like this:

buildspec.yaml

version: 0.2

phases:
  pre_build:
    commands:
      - ./dagger.sh
  build:
    commands:
      - ./test.sh

dagger.sh:

#!/bin/bash -eu

echo "Installing Dagger CLI"
curl -L https://dl.dagger.io/dagger/install.sh | BIN_DIR=$HOME/.local/bin sh

test.sh:

#!/bin/bash -eu

docker login --username ${DOCKER_HUB_USER} --password-stdin <<< "${DOCKER_HUB_TOKEN}"
~/.local/bin/dagger develop
~/.local/bin/dagger call test --source=.

dagger/main.go:


package main

import "context"

type Build struct{}

// Test returns the result of running unit tests
func (m *Build) Test(ctx context.Context, source *Directory) (string, error) {
    return m.BuildEnv(source).
        WithExec([]string{"sh", "-c", "go test -v -cover -covermode=atomic ./..."}).
        Stdout(ctx)
}

// BuildEnv builds a ready-to-use development environment
func (m *Build) BuildEnv(source *Directory) *Container {
    cache := dag.CacheVolume("golang")

    return dag.Container().
        From("golang:bullseye").
        WithWorkdir("/go/src/app").
        WithMountedCache("/root/.cache/go-build", cache).
        WithFiles("./", []*File{source.File("go.mod"), source.File("go.sum")}).
        WithExec([]string{"go", "mod", "download"}).
        WithDirectory("/go/src/app", source)
}
#

Original build

buildspec.yaml:

version: 0.2

phases:
  build:
    commands:
      - ./test.sh

test.sh:

#!/bin/bash -eu

docker login --username ${DOCKER_HUB_USER} --password-stdin <<< "${DOCKER_HUB_TOKEN}"
make dtest

Makefile (relevant entries):

COVERAGE := coverage.out
SRC := $(shell find . -name \*.go)
PACKAGES := $(shell go list ./... | grep -v '/cmd/')

.PHONY: dtest
dtest:
    docker build -f Dockerfile.test .

.PHONY: test
test: $(COVERAGE)

$(COVERAGE): $(SRC)
    go test -v -cover -covermode atomic -coverprofile $(COVERAGE) $(PACKAGES)

Dockerfile.test:

FROM golang:bullseye AS build

ARG GIT_SHA="dev"

WORKDIR /go/src/app

COPY go.mod go.sum ./
RUN go mod download

COPY . ./
RUN echo ${GIT_SHA}; make test
#

Note: the /cmd/ is a handful of "CI" tools but they don't contribute anything much to build time and have very few tests of consequence.

jovial spoke
gaunt fossil
#

I can connect it briefly so we can capture a build execution but I don’t think I’d be able to keep it permanently connected without sign off as a cloud vendor.