Skip to content

Commit

Permalink
v0.2.0 ImagePuller as aceptadora.New() param
Browse files Browse the repository at this point in the history
Instead of instantiating ImagePuller for each aceptadora, we now can
reuse a global one (for the test suite). This will avoid pulling same
image for each test where a new aceptadora is created every time.

We need this as docker repository is now imposing rate limit and
introducing latency on docker pulls, and we're seeing times of up to
2.5s to just check that we have the latest image.

This is a breaking change.
  • Loading branch information
colega committed Nov 18, 2020
1 parent 4f86183 commit 7604291
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 13 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.2.0] - 2020-11-18
### Changed
- BREAKING: `aceptadora.New()` now accepts an `ImagePuller` instead of creating it, and `aceptadora.Config` no longer contains the `aceptadora.ImagePullerConfig`.
This allows reusing same ImagePuller for multiple aceptadora instances (one per test probably) and taking advantage of the image cache that `ImagePuller` has to avoid pulling same image multiple times.

## [0.1.0] - 2020-10-14
### Added
- Initial public version
Expand Down
8 changes: 4 additions & 4 deletions acceptance/config/default.env
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Specific config for acceptance tester
# This domain is skipped as it's used for images built locally
ACCEPTANCE_ACEPTADORA_IMAGEPULLER_REPO_0_DOMAIN=cabify.local
ACCEPTANCE_ACEPTADORA_IMAGEPULLER_REPO_0_SKIPPULLING=true
ACCEPTANCE_IMAGEPULLER_REPO_0_DOMAIN=company.local
ACCEPTANCE_IMAGEPULLER_REPO_0_SKIPPULLING=true

# Don't pull gitlab otherwise we need credentials
# Pull the images manually for the test please
ACCEPTANCE_ACEPTADORA_IMAGEPULLER_REPO_1_DOMAIN=gitlab.com
ACCEPTANCE_ACEPTADORA_IMAGEPULLER_REPO_1_SKIPPULLING=true
ACCEPTANCE_IMAGEPULLER_REPO_1_DOMAIN=gitlab.com
ACCEPTANCE_IMAGEPULLER_REPO_1_SKIPPULLING=true

# ACCEPTANCE_SERVICESADDRESS tells our acceptance suite where the running services are binding their ports
ACCEPTANCE_SERVICESADDRESS=127.0.0.1
6 changes: 3 additions & 3 deletions acceptance/config/gitlab.env
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Specific config for acceptance tester
ACCEPTANCE_ACEPTADORA_IMAGEPULLER_REPO_0_DOMAIN=${CI_REGISTRY}
ACCEPTANCE_ACEPTADORA_IMAGEPULLER_REPO_0_USERNAME=gitlab-ci-token
ACCEPTANCE_ACEPTADORA_IMAGEPULLER_REPO_0_PASSWORD=${CI_JOB_TOKEN}
ACCEPTANCE_IMAGEPULLER_REPO_0_DOMAIN=${CI_REGISTRY}
ACCEPTANCE_IMAGEPULLER_REPO_0_USERNAME=gitlab-ci-token
ACCEPTANCE_IMAGEPULLER_REPO_0_PASSWORD=${CI_JOB_TOKEN}

# ACCEPTANCE_SERVICESADDRESS tells our acceptance suite where the running services are binding their ports
# In case of gitlab, this is the docker-in-docker host, which is `docker`
Expand Down
6 changes: 4 additions & 2 deletions acceptance/suite/acceptance_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ import (
const expectedMockedDependencyInventedHTTPStatusCode = 288

type Config struct {
Aceptadora aceptadora.Config
Aceptadora aceptadora.Config
ImagePuller aceptadora.ImagePullerConfig

// ServicesAddress is the address where services started by aceptadora can be found
// It differs from env to env, and it's set up in env-specific configs
Expand Down Expand Up @@ -46,7 +47,8 @@ func (s *acceptanceSuite) SetupSuite() {
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute)
defer cancel()

s.aceptadora = aceptadora.New(s.T(), s.cfg.Aceptadora)
imagePuller := aceptadora.NewImagePuller(s.T(), s.cfg.ImagePuller)
s.aceptadora = aceptadora.New(s.T(), imagePuller, s.cfg.Aceptadora)
s.aceptadora.PullImages(ctx)

s.startMockedProxyDependency()
Expand Down
6 changes: 2 additions & 4 deletions aceptadora.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ import (
type Config struct {
YAMLDir string `default:"./"`
YAMLName string `default:"aceptadora.yml"`

ImagePuller ImagePullerConfig
}

type Aceptadora struct {
Expand All @@ -34,7 +32,7 @@ type Aceptadora struct {

// New creates a new Aceptadora. It will try to load the YAML config from the path provided by Config
// If something goes wrong, it will use testing.T to fail.
func New(t *testing.T, cfg Config) *Aceptadora {
func New(t *testing.T, imagePuller ImagePuller, cfg Config) *Aceptadora {
if _, ok := os.LookupEnv("TESTER_ADDRESS"); !ok {
os.Setenv("TESTER_ADDRESS", getLocalIP())
}
Expand All @@ -49,7 +47,7 @@ func New(t *testing.T, cfg Config) *Aceptadora {
require: require.New(t),
cfg: cfg,
yaml: yaml,
imagePuller: NewImagePuller(t, cfg.ImagePuller),
imagePuller: imagePuller,
services: map[string]*Runner{},
}
}
Expand Down

0 comments on commit 7604291

Please sign in to comment.