Skip to content

Commit

Permalink
Do not explicitely pull images, rely on podman api instead (#68)
Browse files Browse the repository at this point in the history
* Do not explicitely pull images, rely on podman api instead

 Fixed #67

* Improve buildscripts, maintain CHANGELOG
  • Loading branch information
towe75 authored Nov 5, 2020
1 parent 56ad1cb commit 52db084
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 64 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ jobs:

steps:
- uses: actions/checkout@v1
- uses: actions/setup-go@v2
with:
go-version: '^1.14.1'

- name: Show go version
run: go version

- name: Lint Deps
run: make lint-deps
Expand Down
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@

FEATURES:

* config: Ability to configure dns server list
* config: [[GH-54](https://github.com/hashicorp/nomad-driver-podman/issues/54)] Ability to configure dns server list
* runtime: [[GH-64](https://github.com/hashicorp/nomad-driver-podman/issues/64)] Add support for SignalTask

BUG FIXES:

* [[GH-67](https://github.com/hashicorp/nomad-driver-podman/issues/67)] run container from oci-archive image

## 0.1.0

Expand Down
10 changes: 5 additions & 5 deletions GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ changelogfmt:
.PHONY: check
check: ## Lint the source code
@echo "==> Linting source code..."
@golangci-lint run
@$(CURDIR)/build/bin/golangci-lint run
@echo "==> vetting hc-log statements"
@hclogvet .
@$(CURDIR)/build/bin/hclogvet $(CURDIR)

.PHONY: lint-deps
lint-deps: ## Install linter dependencies
## Keep versions in sync with tools/go.mod (see https://github.com/golang/go/issues/30515)
@echo "==> Updating linter dependencies..."
GO111MODULE=on cd tools && go get github.com/golangci/golangci-lint/cmd/[email protected]
GO111MODULE=on cd tools && go get github.com/client9/misspell/cmd/[email protected]
GO111MODULE=on cd tools && go get github.com/hashicorp/go-hclog/hclogvet@master
cd tools && GOBIN=$(CURDIR)/build/bin go get github.com/golangci/golangci-lint/cmd/[email protected]
cd tools && GOBIN=$(CURDIR)/build/bin go get github.com/client9/misspell/cmd/[email protected]
cd tools && GOBIN=$(CURDIR)/build/bin go get github.com/hashicorp/go-hclog/hclogvet@master
57 changes: 2 additions & 55 deletions driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@ package main
import (
"context"
"fmt"
"github.com/hashicorp/consul-template/signals"
"os/user"
"path/filepath"
"strings"
"time"

"github.com/hashicorp/consul-template/signals"

"github.com/hashicorp/nomad/nomad/structs"

"github.com/hashicorp/go-hclog"
Expand Down Expand Up @@ -356,12 +357,6 @@ func (d *Driver) StartTask(cfg *drivers.TaskConfig) (*drivers.TaskHandle, *drive
return nil, nil, fmt.Errorf("image name required")
}

img, err := d.createImage(cfg, &driverConfig)
if err != nil {
return nil, nil, fmt.Errorf("Couldn't create image: %v", err)
}
d.logger.Debug("created/pulled image", "img_id", img.ID)

allArgs := []string{driverConfig.Image}
if driverConfig.Command != "" {
allArgs = append(allArgs, driverConfig.Command)
Expand Down Expand Up @@ -690,54 +685,6 @@ func (d *Driver) ExecTask(taskID string, cmd []string, timeout time.Duration) (*
return nil, fmt.Errorf("Podman driver does not support exec")
}

func (d *Driver) createImage(cfg *drivers.TaskConfig, driverConfig *TaskConfig) (iopodman.InspectImageData, error) {
img, err := d.podmanClient.InspectImage(driverConfig.Image)
if err != nil {
err = d.eventer.EmitEvent(&drivers.TaskEvent{
TaskID: cfg.ID,
AllocID: cfg.AllocID,
TaskName: cfg.Name,
Timestamp: time.Now(),
Message: "Downloading image",
Annotations: map[string]string{
"image": driverConfig.Image,
},
})
if err != nil {
d.logger.Warn("error emitting event", "error", err)
}

pullLog, err := d.podmanClient.PullImage(driverConfig.Image)
if err != nil {
return iopodman.InspectImageData{}, fmt.Errorf("image %s couldn't be downloaded: %v", driverConfig.Image, err)
}

img, err = d.podmanClient.InspectImage(driverConfig.Image)
if err != nil {
return iopodman.InspectImageData{}, fmt.Errorf("image %s couldn't be inspected: %v", driverConfig.Image, err)
}

err = d.eventer.EmitEvent(&drivers.TaskEvent{
TaskID: cfg.ID,
AllocID: cfg.AllocID,
TaskName: cfg.Name,
Timestamp: time.Now(),
Message: fmt.Sprintf("Image downloaded: %s", pullLog),
Annotations: map[string]string{
"image": driverConfig.Image,
},
})
if err != nil {
d.logger.Warn("error emitting event", "error", err)
}

}

d.logger.Debug("Image created", "img_id", img.ID, "config", img.Config)

return img, nil
}

func (d *Driver) containerBinds(task *drivers.TaskConfig, driverConfig *TaskConfig) ([]string, error) {
allocDirBind := fmt.Sprintf("%s:%s", task.TaskDir().SharedAllocDir, task.Env[taskenv.AllocDir])
taskLocalBind := fmt.Sprintf("%s:%s", task.TaskDir().LocalDir, task.Env[taskenv.TaskLocalDir])
Expand Down

0 comments on commit 52db084

Please sign in to comment.