Skip to content

Commit

Permalink
Merge pull request #377 from nitrictech/develop
Browse files Browse the repository at this point in the history
Release
  • Loading branch information
HomelessDinosaur authored Nov 2, 2022
2 parents cba13c8 + 9ffc259 commit 94563f0
Show file tree
Hide file tree
Showing 56 changed files with 1,298 additions and 2,693 deletions.
3 changes: 0 additions & 3 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,8 @@ linters:
- gofumpt
- whitespace
- staticcheck
- structcheck
- ineffassign
- varcheck
- unused
- deadcode
- misspell
- unconvert
- errcheck
Expand Down
16 changes: 7 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ RUN apt-get update -y && \
pass \
unzip && \
# Get all of the signatures we need all at once.
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource.gpg.key | apt-key add - && \
curl -fsSL https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - && \
curl -fsSL https://download.docker.com/linux/debian/gpg | apt-key add - && \
# IAM Authenticator for EKS
curl -fsSLo /usr/bin/aws-iam-authenticator https://amazon-eks.s3-us-west-2.amazonaws.com/1.10.3/2018-07-26/bin/linux/amd64/aws-iam-authenticator && \
Expand All @@ -47,16 +45,10 @@ RUN apt-get update -y && \
./aws/install && \
rm -rf aws && \
# Add additional apt repos all at once
echo "deb https://deb.nodesource.com/node_14.x $(lsb_release -cs) main" | tee /etc/apt/sources.list.d/node.list && \
echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list && \
echo "deb [arch=amd64] https://download.docker.com/linux/debian $(lsb_release -cs) stable" | tee /etc/apt/sources.list.d/docker.list && \
# Install second wave of dependencies
apt-get update -y && \
apt-get install -y \
docker-ce \
amazon-ecr-credential-helper \
nodejs \
yarn && \
apt-get install -y docker-ce && \
# Clean up the lists work
rm -rf /var/lib/apt/lists/*

Expand All @@ -69,6 +61,12 @@ ARG PULUMI_VERSION
RUN curl -fsSL https://get.pulumi.com/ | bash -s -- --version $PULUMI_VERSION && \
mv ~/.pulumi/bin/* /usr/bin

RUN curl -fsSLo /tmp/dch.tgz https://github.com/docker/docker-credential-helpers/releases/download/${DOCKER_PASS_CH}/docker-credential-pass-${DOCKER_PASS_CH}-amd64.tar.gz; \
tar -xf /tmp/dch.tgz; \
chmod +x docker-credential-pass; \
mv -f docker-credential-pass /usr/bin/; \
rm -rf /tmp/dch.tgz

ENV HOST_DOCKER_INTERNAL_IFACE eth0
ENV PULUMI_SKIP_UPDATE_CHECK "true"

Expand Down
192 changes: 98 additions & 94 deletions go.mod

Large diffs are not rendered by default.

1,467 changes: 339 additions & 1,128 deletions go.sum

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions mocks/mock_containerengine/mock_containerengine.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 9 additions & 20 deletions pkg/build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"fmt"
"os"
"path/filepath"
"strings"

"github.com/nitrictech/cli/pkg/containerengine"
"github.com/nitrictech/cli/pkg/project"
Expand All @@ -29,32 +28,24 @@ import (

func dynamicDockerfile(dir, name string) (*os.File, error) {
// create a more stable file name for the hashing
return os.CreateTemp(dir, "nitric.dynamic.Dockerfile.*")
return os.Create(filepath.Join(dir, fmt.Sprintf("%s.nitric.dynamic.dockerfile", name)))
}

// CreateBaseDev builds images for code-as-config
func CreateBaseDev(s *project.Project) error {
// Build base non-nitric wrapped docker image
// These will also be used for config as code runs
func BuildBaseImages(s *project.Project) error {
ce, err := containerengine.Discover()
if err != nil {
return err
}

imagesToBuild := map[string]string{}

for _, f := range s.Functions {
rt, err := runtime.NewRunTimeFromHandler(f.Handler)
for _, fun := range s.Functions {
rt, err := runtime.NewRunTimeFromHandler(fun.Handler)
if err != nil {
return err
}

lang := strings.Replace(filepath.Ext(f.Handler), ".", "", 1)

_, ok := imagesToBuild[lang]
if ok {
continue
}

f, err := dynamicDockerfile(s.Dir, f.Name)
f, err := dynamicDockerfile(s.Dir, fun.Name)
if err != nil {
return err
}
Expand All @@ -64,15 +55,13 @@ func CreateBaseDev(s *project.Project) error {
os.Remove(f.Name())
}()

if err := rt.FunctionDockerfileForCodeAsConfig(f); err != nil {
if err := rt.BaseDockerFile(f); err != nil {
return err
}

if err := ce.Build(filepath.Base(f.Name()), s.Dir, rt.DevImageName(), map[string]string{}, rt.BuildIgnore()); err != nil {
if err := ce.Build(filepath.Base(f.Name()), s.Dir, fmt.Sprintf("%s-%s", s.Name, fun.Name), rt.BuildArgs(), rt.BuildIgnore()); err != nil {
return err
}

imagesToBuild[lang] = rt.DevImageName()
}

return nil
Expand Down
10 changes: 5 additions & 5 deletions pkg/build/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
"github.com/nitrictech/cli/pkg/project"
)

func TestCreateBaseDev(t *testing.T) {
func TestBuildBaseImages(t *testing.T) {
ctrl := gomock.NewController(t)
me := mock_containerengine.NewMockContainerEngine(ctrl)

Expand All @@ -39,15 +39,15 @@ func TestCreateBaseDev(t *testing.T) {
defer os.RemoveAll(dir)

s := project.New(&project.Config{Name: "", Dir: dir})
s.Functions = map[string]project.Function{"foo": {Handler: "functions/list.ts"}}
s.Functions = map[string]project.Function{"foo": {Handler: "functions/list.ts", ComputeUnit: project.ComputeUnit{Name: "foo"}}}

me.EXPECT().Build(gomock.Any(), dir, "nitric-ts-dev", map[string]string{}, []string{
".nitric/", ".git/", ".idea/", ".vscode/", ".github", "node_modules/",
me.EXPECT().Build(gomock.Any(), dir, "-foo", gomock.Any(), []string{
".nitric/", ".git/", ".idea/", ".vscode/", ".github/", "*.dockerfile", "*.dockerignore", "node_modules/",
})

containerengine.DiscoveredEngine = me

if err := CreateBaseDev(s); err != nil {
if err := BuildBaseImages(s); err != nil {
t.Errorf("CreateBaseDev() error = %v", err)
}
}
44 changes: 9 additions & 35 deletions pkg/cmd/run/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"log"
"os"
"os/signal"
"strings"
"sync"
"syscall"
"time"
Expand All @@ -32,7 +31,6 @@ import (
"github.com/spf13/cobra"

"github.com/nitrictech/cli/pkg/build"
"github.com/nitrictech/cli/pkg/codeconfig"
"github.com/nitrictech/cli/pkg/containerengine"
"github.com/nitrictech/cli/pkg/output"
"github.com/nitrictech/cli/pkg/project"
Expand All @@ -51,11 +49,11 @@ var runCmd = &cobra.Command{
Annotations: map[string]string{"commonCommand": "yes"},
Run: func(cmd *cobra.Command, args []string) {
term := make(chan os.Signal, 1)
signal.Notify(term, os.Interrupt, syscall.SIGTERM)
signal.Notify(term, os.Interrupt, syscall.SIGINT)
signal.Notify(term, syscall.SIGTERM, syscall.SIGINT)

// Divert default log output to pterm debug
log.SetOutput(output.NewPtermWriter(pterm.Debug))
log.SetFlags(0)

config, err := project.ConfigFromProjectPath("")
cobra.CheckErr(err)
Expand All @@ -70,16 +68,6 @@ var runCmd = &cobra.Command{
cobra.CheckErr(err)
}

codeAsConfig := tasklet.Runner{
StartMsg: "Gathering configuration from code...",
Runner: func(_ output.Progress) error {
proj, err = codeconfig.Populate(proj, envMap)
return err
},
StopMsg: "Configuration gathered",
}
tasklet.MustRun(codeAsConfig, tasklet.Opts{})

ls := run.NewLocalServices(proj)
if ls.Running() {
pterm.Error.Println("Only one instance of Nitric can be run locally at a time, please check that you have ended all other instances and try again")
Expand All @@ -93,11 +81,11 @@ var runCmd = &cobra.Command{
cobra.CheckErr(logger.Start())

createBaseImage := tasklet.Runner{
StartMsg: "Creating development image",
StartMsg: "Building Images",
Runner: func(_ output.Progress) error {
return build.CreateBaseDev(proj)
return build.BuildBaseImages(proj)
},
StopMsg: "Development image created",
StopMsg: "Images Built",
}
tasklet.MustRun(createBaseImage, tasklet.Opts{Signal: term})

Expand Down Expand Up @@ -157,9 +145,11 @@ var runCmd = &cobra.Command{

pterm.DefaultBasicText.Println("Application running, use ctrl-C to stop")

stackState := run.NewStackState()
stackState := run.StateFromPool(pool)

area, _ := pterm.DefaultArea.Start()
area.Update(stackState.Tables(9001))

lck := sync.Mutex{}
// React to worker pool state and update services table
pool.Listen(func(we run.WorkerEvent) {
Expand All @@ -168,23 +158,7 @@ var runCmd = &cobra.Command{
// area.Clear()

stackState.UpdateFromWorkerEvent(we)

tables := []string{}
table, rows := stackState.ApiTable(9001)
if rows > 0 {
tables = append(tables, table)
}

table, rows = stackState.TopicTable(9001)
if rows > 0 {
tables = append(tables, table)
}

table, rows = stackState.SchedulesTable(9001)
if rows > 0 {
tables = append(tables, table)
}
area.Update(strings.Join(tables, "\n\n"))
area.Update(stackState.Tables(9001))
})

select {
Expand Down
Loading

0 comments on commit 94563f0

Please sign in to comment.