Skip to content
This repository has been archived by the owner on Jul 16, 2021. It is now read-only.

Icons processing and exposure #98

Merged
merged 1 commit into from
Feb 9, 2017

Conversation

migmartri
Copy link
Contributor

@migmartri migmartri commented Feb 8, 2017

  • Moved helper files to custom package (charthelper)
  • Downloads and process icons
  • Added static files middleware under /assets (we could eventually put Nginx to serve this path directly instead)
  • Remove Readme file endpoint and exposed now via the static middleware.
  • Exposes processed icons via the static middleware
  • Icons and README static paths are exposed via the API

Chart endpoint:
selection_110

  • The backend now serves the static files directory that contains those files.

selection_109

Closes #43

@migmartri migmartri added the wip label Feb 8, 2017
defer func() { downloadAndExtractChartTarball = downloadAndExtractChartTarballOrig }()
knownError := errors.New("error on downloadAndExtractChartTarball")
downloadAndExtractChartTarball = func(chart *models.ChartPackage) error {
ChartDataExistsOrig := charthelper.ChartDataExists
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm new on Go, so sorry about the question :P. Why do you capitalize the first letter of variables? Is this a convention?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This means that it is exported so it can be referenced in other packages.

Copy link
Member

@Angelmmiguel Angelmmiguel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update processIcon to generate icons using fit or fill methods

height int
}

var availableFormats = []iconFormat{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the current configuration we are generating images that fill the given height and width. For example, for Traefik the output is:

lTraefik 100 x 100

The problem is the logo is cropped, so some parts of the logo are missing. For image backgrounds is okey because we want to fill it as much as possible. But, for cards we want to show the entire logo. I think we can add another attribute to iconFormat called strategy to switch between fill and fit methods:

// Strategy resizing method type
type StrategyType uint8

const(
  FIT StrategyType = iota
  FILL
)

type iconFormat struct {
  name         string
  strategy     StrategyType
  width        int
  height       int
}


var availableFormats = []iconFormat{
  {"100x100", FILL, 100, 100},
  {"300x300", FILL, 300, 300},
  {"100x100fit", FIT, 100, 100},
  {"300x300fit", FIT, 300, 300},
}

This parameter allow us to use an fill or fit strategy to resize and crop the image. The result for the same logo is:

Traefik 100x100fit

I know this image doesn't measure 100 x 100px, but fit method ensures me that the maximum height or width will be 100px. So, I can center it using background properties in the CSS.

We need to update the processIcon method to check the strategy:

var processed *image.NRGBA
if format.strategy == FILL {
  processed = imaging.Fill(orig, format.width, format.height, imaging.Center, imaging.Lanczos)
} else {
  processed = imaging.Fit(orig, format.width, format.height, imaging.Lanczos)
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Angelmmiguel it makes a lot of sense, thanks a lot!

To reduce computation penalty I'd like to reduce the number of processed icons to the minimum. What's in your take the formats (width, height and strategy) that we will need?

@migmartri migmartri changed the title 43 image processing Icons processing and exposure Feb 8, 2017
@codecov-io
Copy link

codecov-io commented Feb 8, 2017

Codecov Report

Merging #98 into master will increase coverage by 0.14%.

@@            Coverage Diff             @@
##           master      #98      +/-   ##
==========================================
+ Coverage   84.92%   85.06%   +0.14%     
==========================================
  Files          11       12       +1     
  Lines         597      663      +66     
==========================================
+ Hits          507      564      +57     
- Misses         61       67       +6     
- Partials       29       32       +3
Impacted Files Coverage Δ
src/api/handlers/sorting.go 100% <ø> (ø)
src/api/mocks/charts.go 79.77% <ø> (-1.08%)
src/api/handlers/charts.go 83.63% <100%> (-2.94%)
src/api/data/cache/cache.go 88.76% <100%> (+0.12%)
src/api/data/helpers/helpers.go 96.38% <100%> (+0.11%)
...api/data/cache/charthelper/chart_package_helper.go 76% <55.55%> (ø)
src/api/data/cache/charthelper/icon_helper.go 90.27% <90.27%> (ø)
src/api/jobs/jobs.go 78.94% <ø> (+15.78%)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8c649a9...50f0e50. Read the comment docs.

Copy link
Contributor

@jackfrancis jackfrancis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@migmartri Look who's a gopher! ;)

The decomposition of cache-->charthelper here looks fine. There may be a way to add some helper code in the future to generalize all the manual http.Get() code littered around, but that's not a showstopper.

@migmartri
Copy link
Contributor Author

Thanks @jackfrancis for the review.

Yes, We should definitely iterate and decompose some of that code in different packages with common dependencies for code sharing.

@migmartri migmartri force-pushed the 43-image-processing branch 2 times, most recently from 681319f to f35e005 Compare February 9, 2017 05:16
* Static files middleware
* Add README to middleware
@migmartri migmartri merged commit a6dc291 into helm:master Feb 9, 2017
@migmartri
Copy link
Contributor Author

@Angelmmiguel The icon changes have been merged. As you can see, now the UI does not show any icons since they are using the old icon property.

Now, as part of the chartVersion API we include the different icon sizes that have been processed:

For example, in http://localhost:8080/v1/charts/stable/jenkins you get the following payload.

selection_043

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants