Skip to content
This repository has been archived by the owner on Dec 18, 2024. It is now read-only.

Commit

Permalink
Fix docker-compose/tests to work with refactored Docker image
Browse files Browse the repository at this point in the history
  • Loading branch information
mogul committed Jan 25, 2022
1 parent 441d42e commit c57ed8e
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 50 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ jobs:
- name: checkout
uses: actions/checkout@v2
- name: test
run: docker-compose run --rm test
run: docker compose run --rm test
6 changes: 6 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM cloudfoundry/cflinuxfs3:latest
WORKDIR /home/vcap/app
COPY --chown=vcap:vcap . ./
USER vcap:vcap
ENV HOME=$WORKDIR
CMD ["/bin/bash", "-c", "./.profile && ./start.sh"]
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ applications.

Name | Description
---- | -----------
logstack-logstash | Logstash process that aggregates and parses log data.
logstack-shipper | Logstash process that aggregates and parses log data.
logstack-space-drain | Space drain monitors a CF space, and binds the log drain to applications. Created by the [drains plugin](https://github.com/cloudfoundry/cf-drain-cli).

_Note: The logstack-space-drain application consumes 64MB._
Expand All @@ -78,7 +78,7 @@ _Note: The logstack-space-drain application consumes 64MB._

Run tests.

docker-compose run --rm test
docker compose run --rm test

## Contributing

Expand Down
19 changes: 11 additions & 8 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,14 @@ services:
localstack:
condition: service_healthy
healthcheck:
test: bin/logstash -t
interval: 60s
timeout: 50s
retries: 5
build: logstash
test: "${DOCKER_HEALTHCHECK_TEST:-/usr/bin/curl --fail http://logstash:logstash@localhost:8080 || exit 1}"
interval: 10s
timeout: 3s
start_period: 5s
retries: 20
build:
dockerfile: $PWD/Dockerfile
context: logstash
environment:
AWS_ACCESS_KEY_ID: test
AWS_SECRET_ACCESS_KEY: test
Expand All @@ -49,10 +52,10 @@ services:
AWS_ENDPOINT: http://localstack:4566
DRAIN_USER: logstash
DRAIN_PASSWORD: logstash
PORT: 8080
ports:
- "5044:5044"
- "9600:9600"
- "9700:9700"
- 8080:8080
- 9600:9600

test:
build:
Expand Down
13 changes: 7 additions & 6 deletions logstash/.profile
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,22 @@ function parse_vcap_services () {
parse_vcap_services

echo "Unpacking logstash..."
(cd "$HOME" && tar xzvf logstash-oss-7.16.3-linux-x86_64.tar.gz > /dev/null 2>&1 && rm logstash-oss-7.16.3-linux-x86_64.tar.gz)
export LS_HOME="$HOME/logstash-7.16.3"
tar xzvf logstash-oss-7.16.3-linux-x86_64.tar.gz > /dev/null 2>&1 && \
rm logstash-oss-7.16.3-linux-x86_64.tar.gz
export LS_HOME="$PWD/logstash-7.16.3"

echo "Installing logstash plugins..."
"$LS_HOME"/bin/logstash-plugin install file://"$HOME"/plugins.zip
"$LS_HOME"/bin/logstash-plugin install file://"$PWD"/plugins.zip

echo "Installing Cloud Foundry root CA certificate..."
cp "$LS_HOME"/jdk/lib/security/cacerts "$LS_HOME"/jdk/lib/security/jssecacerts
for cert in "$CF_SYSTEM_CERT_PATH"/* ; do
shopt -s nullglob # Skip the loop if there're no matching files
for cert in "${CF_SYSTEM_CERT_PATH:-/etc/cf-system-certificates}/*" ; do
echo "Installing certificates: $cert"
# We haven't ever seen someone change this default password, and anyone who
# can see this already has permission to update these files, so we're not
# setting anything more complicated to avoid complications down the line.
"$LS_HOME"/jdk/bin/keytool -noprompt -import -trustcacerts -file "$cert" -storepass changeit -alias "${cert/$CF_SYSTEM_CERT_PATH\//}" -keystore "$LS_HOME"/jdk/lib/security/jssecacerts
done

ln -s "$LS_HOME"/bin/logstash "$HOME"/bin/logstash || true

ln -s "$LS_HOME"/bin/logstash "$PWD"/bin/logstash || true
9 changes: 0 additions & 9 deletions logstash/Dockerfile

This file was deleted.

5 changes: 1 addition & 4 deletions logstash/start.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
#!/bin/bash

set -o errexit
set -o pipefail

exec "bin/logstash -f logstash.conf"
exec bin/logstash -f logstash.conf
22 changes: 2 additions & 20 deletions test/test_logstash.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,14 @@

LOGSTASH_HEALTHCHECK = 'http://logstash:9600/?pretty'


class TestLogstash(unittest.TestCase):
@classmethod
def setUpClass(cls):
# Wait for Logstash to be up
while True:
response = None
try:
response = requests.get(LOGSTASH_HEALTHCHECK)
except:
pass

if response and response.status_code == 200:
# Logstash is up, let's continue
break
time.sleep(1)


def test_anonymous_access_denied(self):
response = requests.get('http://logstash:5044')
response = requests.get('http://logstash:8080')
assert response.status_code == 401


def test_authorized_user_allowed(self):
client = requests.Session()
client.auth = ('logstash', 'logstash')

response = client.get('http://logstash:5044')
response = client.get('http://logstash:8080')
assert response.status_code == 200

0 comments on commit c57ed8e

Please sign in to comment.