Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fixed badge generation timeout #170

Merged
merged 1 commit into from
May 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

### Changed
- [#163](https://github.com/devatherock/artifactory-badge/issues/163): Used distroless base docker image
- [#169](https://github.com/devatherock/artifactory-badge/issues/169): Fixed badge generation timeout due to missing reflection config for `io.netty.handler.ssl.SslHandler`

## [1.1.0] - 2022-05-12
### Added
Expand Down
8 changes: 6 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@ DOCKER_TAG=latest
clean:
./gradlew clean
integration-test:
docker-compose up > /dev/null &
./gradlew integrationTest
docker-compose up &
./gradlew integrationTest --tests '*ControllerIntegrationSpec*'
docker-compose down
remote-integration-test:
docker-compose -f docker-compose-remote.yml up &
./gradlew integrationTest --tests '*RemoteUrlsIntegrationSpec*'
docker-compose down
docker-build:
./gradlew clean build -Dgraalvm=true
Expand Down
12 changes: 12 additions & 0 deletions docker-compose-remote.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
version: '2'
services:

artifactory-badge:
image: devatherock/artifactory-badge:latest
network_mode: "host"
environment:
- ARTIFACTORY_URL=http://localhost:8081
- ARTIFACTORY_API_KEY=dummyKey
- LOGBACK_CONFIGURATION_FILE=https://raw.githubusercontent.com/devatherock/artifactory-badge/master/src/main/resources/logback-json.xml
ports:
- "8080:8080"
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ services:
- ARTIFACTORY_URL=http://localhost:8081
- ARTIFACTORY_API_KEY=dummyKey
- ARTIFACTORY_BADGE_SHIELDS_IO_URL=http://localhost:8081
- LOGBACK_CONFIGURATION_FILE=https://raw.githubusercontent.com/devatherock/artifactory-badge/master/src/main/resources/logback-json.xml
- LOGBACK_CONFIGURATION_FILE=logback-json.xml
ports:
- "8080:8080"
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package io.github.devatherock.artifactory.controllers

import io.micronaut.test.extensions.spock.annotation.MicronautTest

/**
* Integration test that calls remote endpoints
*/
@MicronautTest(propertySources = 'classpath:application-integration.yml', startApplication = false)
class RemoteUrlsIntegrationSpec extends RemoteUrlsSpec {
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ import io.micronaut.test.extensions.spock.annotation.MicronautTest
/**
* Unit test for {@link DockerController}
*/
@MicronautTest(startApplication = true)
@MicronautTest
class DockerControllerTestSpec extends DockerControllerSpec {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package io.github.devatherock.artifactory.controllers

import static com.github.tomakehurst.wiremock.client.WireMock.equalTo
import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo

import javax.inject.Inject

import io.github.devatherock.artifactory.service.DockerBadgeService
import io.github.devatherock.test.TestUtil

import com.github.tomakehurst.wiremock.WireMockServer
import com.github.tomakehurst.wiremock.client.WireMock
import io.micronaut.http.HttpRequest
import io.micronaut.http.client.HttpClient
import io.micronaut.http.client.annotation.Client
import io.micronaut.http.uri.UriBuilder
import spock.lang.Shared
import spock.lang.Specification

/**
* Test that calls remote endpoints. Needed for proper netty SSL reflection config
*/
abstract class RemoteUrlsSpec extends Specification {

@Shared
WireMockServer mockServer = new WireMockServer(8081)

@Inject
@Client('${test.server.url}')
HttpClient httpClient

void setupSpec() {
WireMock.configureFor(8081)
mockServer.start()
}

void cleanupSpec() {
mockServer.stop()
}

void cleanup() {
mockServer.resetAll()
}

void 'test get image size'() {
given:
String packageName = 'docker/devatherock/simple-slack'

and:
WireMock.givenThat(WireMock.get("/artifactory/${packageName}/latest/manifest.json")
.willReturn(WireMock.okJson(TestUtil.getManifest())))

when:
String badge = httpClient.toBlocking().retrieve(
HttpRequest.GET(UriBuilder.of('/docker/image-size')
.queryParam('package', packageName).build()))

then:
WireMock.verify(1,
WireMock.getRequestedFor(urlEqualTo("/artifactory/${packageName}/latest/manifest.json"))
.withHeader(DockerBadgeService.HDR_API_KEY, equalTo('dummyKey')))
badge.startsWith('<svg')
badge.endsWith('</svg>')
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package io.github.devatherock.artifactory.controllers

import io.micronaut.test.extensions.spock.annotation.MicronautTest

/**
* Unit test that calls remote endpoints
*/
@MicronautTest(propertySources = ['classpath:application-test.yml', 'classpath:application-remote.yml'])
class RemoteUrlsTestSpec extends RemoteUrlsSpec {
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ import io.micronaut.test.extensions.spock.annotation.MicronautTest
/**
* Unit test for {@link VersionController}
*/
@MicronautTest(startApplication = true)
@MicronautTest
class VersionControllerTestSpec extends VersionControllerSpec {
}
4 changes: 4 additions & 0 deletions src/test/resources/application-remote.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
artifactory:
badge:
shields-io:
url: https://img.shields.io