-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from ba-st/issue_14
Add a basic service discovery test to the build using docker compose
- Loading branch information
Showing
12 changed files
with
261 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,3 @@ | ||
# changes file | ||
*.changes | ||
|
||
# system image | ||
*.image | ||
|
||
# Pharo Smalltalk Debug log file | ||
PharoDebug.log | ||
|
||
# Squeak Smalltalk Debug log file | ||
SqueakDebug.log | ||
|
||
# Monticello package cache | ||
/package-cache | ||
|
||
# Metacello-github cache | ||
/github-cache | ||
github-*.zip | ||
api-tests/.env | ||
api-tests/logs | ||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Stage 1: Load the project | ||
FROM basmalltalk/pharo:8.0-image AS loader | ||
ARG BRANCH_NAME=release-candidate | ||
COPY load-project.st ./ | ||
RUN pharo Pharo.image load-project.st --save --quit | ||
|
||
# Stage 2: Copy the resulting Pharo.image with our project loaded | ||
# into a new docker image with just the vm | ||
FROM basmalltalk/pharo:8.0 | ||
|
||
USER root | ||
|
||
WORKDIR /opt/Superluminal-Service-Discovery-Example | ||
COPY start.sh ./ | ||
COPY --from=loader /opt/pharo/Pharo.image ./ | ||
COPY --from=loader /opt/pharo/Pharo.changes ./ | ||
COPY --from=loader /opt/pharo/Pharo*.sources ./ | ||
|
||
RUN mkdir logs \ | ||
&& chmod a+x start.sh \ | ||
&& chown --recursive pharo:users /opt/Superluminal-Service-Discovery-Example | ||
|
||
USER pharo | ||
|
||
CMD ["./start.sh"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
version: '3' | ||
services: | ||
api: | ||
image: ghcr.io/ba-st/stargate-consul-example:release-candidate | ||
ports: | ||
- "8080:8080" | ||
environment: | ||
PUBLIC_URL: http://api:8080 | ||
OPERATIONS_SECRET: API-tests | ||
HEALTH_CHECK_TOKEN: eyJhbGciOiJIUzI1NiJ9.eyJzY29wZSI6ImV4ZWN1dGU6aGVhbHRoLWNoZWNrIn0.FQgIMpaHZX_7yPWRNC5HAsmlYWkNYu0pdNrSil3ECRc | ||
APPLICATION_CONTROL_TOKEN: eyJhbGciOiJIUzI1NiJ9.eyJzY29wZSI6ImV4ZWN1dGU6YXBwbGljYXRpb24tY29udHJvbCJ9.CCMnq-6mlX-ZoSC2OfwdBOVn5DILmahP58hfXowjqFk | ||
CONSUL_AGENT_LOCATION: http://consul-agent:8500 | ||
depends_on: | ||
- consul-agent | ||
consul-agent: | ||
image: consul:1.8 | ||
ports: | ||
- "8500:8500" | ||
- "8600:8600" | ||
- "8300:8300" | ||
environment: | ||
CONSUL_BIND_INTERFACE: eth0 | ||
api-client: | ||
build: | ||
context: ./ | ||
args: | ||
- BRANCH_NAME | ||
environment: | ||
MESSAGE: 'Hello' | ||
CONSUL_AGENT_LOCATION: http://consul-agent:8500 | ||
depends_on: | ||
- consul-agent | ||
- api |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
| branchName | | ||
|
||
EpMonitor current disable. | ||
|
||
branchName := Smalltalk os environment at: 'BRANCH_NAME' ifAbsent: [Error signal: 'BRANCH_NAME environment variable not set']. | ||
branchName ifEmpty: [ Error signal: 'BRANCH_NAME environment variable value is empty']. | ||
|
||
Metacello new | ||
baseline: 'Superluminal'; | ||
repository: ('github://ba-st/Superluminal:<1s>' expandMacrosWith: branchName); | ||
load: 'Examples'. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/usr/bin/env bash | ||
|
||
exec /opt/pharo/pharo \ | ||
/opt/Superluminal-Service-Discovery-Example/Pharo.image \ | ||
super-luminal-service-discovery \ | ||
--message="${MESSAGE}" \ | ||
--consul-agent-location="${CONSUL_AGENT_LOCATION}" \ | ||
--retry-delay-in-ms=10000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -e | ||
|
||
if [[ -z "${GITHUB_HEAD_REF##*/}" ]]; then | ||
echo "BRANCH_NAME=${GITHUB_REF##*/}" > .env | ||
else | ||
echo "BRANCH_NAME=${GITHUB_HEAD_REF##*/}" > .env | ||
fi | ||
set +e # disable exit on error to be able to catch the exit code from compose | ||
docker-compose -f api-tests/docker-compose.yml up --exit-code-from api-client |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
...Service-Discovery-Examples-Tests/SuperluminalServiceDiscoveryExampleLauncherTest.class.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
" | ||
A SuperluminalServiceDiscoveryExampleLauncherTest is a test class for testing the behavior of SuperluminalServiceDiscoveryExampleLauncher | ||
" | ||
Class { | ||
#name : #SuperluminalServiceDiscoveryExampleLauncherTest, | ||
#superclass : #TestCase, | ||
#category : #'Superluminal-Service-Discovery-Examples-Tests' | ||
} | ||
|
||
{ #category : #tests } | ||
SuperluminalServiceDiscoveryExampleLauncherTest >> testActivate [ | ||
|
||
self | ||
should: [ | ||
| launcher | | ||
|
||
launcher := SuperluminalServiceDiscoveryExampleLauncher new. | ||
launcher | ||
commandLine: ( CommandLineArguments withArguments: | ||
#( '--consul-agent-location=http://consul:8500' | ||
'--message=Hello' '--retry-delay-in-ms=1' '--debug-mode' ) ); | ||
activate | ||
] | ||
raise: NameLookupFailure | ||
] | ||
|
||
{ #category : #tests } | ||
SuperluminalServiceDiscoveryExampleLauncherTest >> testArguments [ | ||
|
||
| launcher | | ||
|
||
launcher := SuperluminalServiceDiscoveryExampleLauncher new. | ||
launcher commandLine: ( CommandLineArguments withArguments: | ||
#( '--consul-agent-location=http://consul:8500' '--message=Hello' '--retry-delay-in-ms=1' | ||
'--debug-mode' ) ). | ||
|
||
self | ||
assert: launcher message equals: 'Hello'; | ||
assertUrl: launcher consulAgentLocation equals: 'http://consul:8500' | ||
] | ||
|
||
{ #category : #tests } | ||
SuperluminalServiceDiscoveryExampleLauncherTest >> testCommandName [ | ||
|
||
self assert: SuperluminalServiceDiscoveryExampleLauncher commandName | ||
equals: 'super-luminal-service-discovery' | ||
] | ||
|
||
{ #category : #tests } | ||
SuperluminalServiceDiscoveryExampleLauncherTest >> testDescription [ | ||
|
||
self assert: SuperluminalServiceDiscoveryExampleLauncher description | ||
equals: 'I''m a command line example using as dependency an echo API' | ||
] | ||
|
||
{ #category : #tests } | ||
SuperluminalServiceDiscoveryExampleLauncherTest >> testLogPrefix [ | ||
|
||
self assert: SuperluminalServiceDiscoveryExampleLauncher logPrefix | ||
equals: 'Superluminal-Service-Discovery' | ||
] |
1 change: 1 addition & 0 deletions
1
source/Superluminal-Service-Discovery-Examples-Tests/package.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Package { #name : #'Superluminal-Service-Discovery-Examples-Tests' } |
82 changes: 82 additions & 0 deletions
82
...erluminal-Service-Discovery-Examples/SuperluminalServiceDiscoveryExampleLauncher.class.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
Class { | ||
#name : #SuperluminalServiceDiscoveryExampleLauncher, | ||
#superclass : #LaunchpadCommandLineHandler, | ||
#category : #'Superluminal-Service-Discovery-Examples' | ||
} | ||
|
||
{ #category : #accessing } | ||
SuperluminalServiceDiscoveryExampleLauncher class >> commandName [ | ||
|
||
^'super-luminal-service-discovery' | ||
] | ||
|
||
{ #category : #accessing } | ||
SuperluminalServiceDiscoveryExampleLauncher class >> description [ | ||
|
||
^ 'I''m a command line example using as dependency an echo API' | ||
] | ||
|
||
{ #category : #'private - accessing' } | ||
SuperluminalServiceDiscoveryExampleLauncher class >> logPrefix [ | ||
|
||
^ 'Superluminal-Service-Discovery' | ||
] | ||
|
||
{ #category : #'private - activation' } | ||
SuperluminalServiceDiscoveryExampleLauncher >> basicActivate [ | ||
|
||
| consulAgentLocation echoServiceLocation | | ||
|
||
consulAgentLocation := self consulAgentLocation. | ||
CurrentLogger value logAsInfo: 'Discovering dependencies' during: [ | ||
echoServiceLocation := Retry | ||
value: [ | ||
( ConsulAgentHttpAPIBasedDiscoveryClient queryingAgentOn: | ||
consulAgentLocation ) withLocationOfService: #echo | ||
do: [ :location | location ] | ||
ifUnable: [ Error signal: 'Cannot discover #echo service' ] | ||
] | ||
configuredBy: [ :retry | | ||
retry | ||
upTo: 3 timesEvery: ( self configuration at: 'retry-delay-in-ms' ); | ||
on: Error evaluating: [ :attemptNumber :exception | | ||
CurrentLogger value logAsWarning: | ||
( 'Attempt #<1p> failed with error: <2s>' expandMacrosWith: | ||
attemptNumber | ||
with: exception messageText ) | ||
] | ||
] | ||
]. | ||
|
||
RESTfulAPIClient default | ||
get: ( echoServiceLocation | ||
scheme: #http; | ||
addPathSegment: 'echo'; | ||
addPathSegment: self message; | ||
yourself ) | ||
withSuccessfulResponseDo: [ :response | | ||
response = self message asUppercase ifFalse: [ Error signal: 'Invalid response received' ] ]. | ||
|
||
self exitSuccess | ||
] | ||
|
||
{ #category : #'private - accessing' } | ||
SuperluminalServiceDiscoveryExampleLauncher >> configurationDefinition [ | ||
|
||
^ Array | ||
with: ( MandatoryArgument named: 'message' ) | ||
with: ( MandatoryArgument named: 'consul-agent-location' convertingWith: #asUrl ) | ||
with: ( OptionalArgument named: 'retry-delay-in-ms' defaultingTo: 200 convertingWith: [:parameter | parameter asNumber milliSeconds ]) | ||
] | ||
|
||
{ #category : #'private - accessing' } | ||
SuperluminalServiceDiscoveryExampleLauncher >> consulAgentLocation [ | ||
|
||
^ self configuration at: 'consul-agent-location' | ||
] | ||
|
||
{ #category : #'private - accessing' } | ||
SuperluminalServiceDiscoveryExampleLauncher >> message [ | ||
|
||
^ self configuration at: 'message' | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Package { #name : #'Superluminal-Service-Discovery-Examples' } |