Skip to content

Commit

Permalink
Merge pull request #61 from cyber-dojo/simplify-dir-structure
Browse files Browse the repository at this point in the history
Simplify dir structure
  • Loading branch information
JonJagger authored Oct 28, 2024
2 parents 3ac62c8 + e9d27a2 commit ec6309d
Show file tree
Hide file tree
Showing 81 changed files with 175 additions and 197 deletions.
2 changes: 1 addition & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
*
!code/
!source/server/
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ jobs:
- name: Run Rubocop lint on source
id: lint
run:
make lint
make rubocop_lint

- name: Setup Kosli CLI
if: ${{ github.ref == 'refs/heads/main' && (success() || failure()) }}
Expand Down
72 changes: 33 additions & 39 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ Lint/EmptyBlock:

Layout/EmptyLineAfterMagicComment:
Exclude:
- code/**/*
- client/code/**/*
- source/server/**/*
- source/client/**/*
- test/**/*

Layout/LineLength:
Exclude:
- client/code/demo.rb
- source/client/demo.rb
- test/lib/simplecov_json.rb

Lint/PercentStringArray:
Expand All @@ -23,11 +23,9 @@ Lint/PercentStringArray:

Lint/RescueException:
Exclude:
- client/code/dispatcher.rb
- client/code/rack_dispatcher.rb
- code/dispatcher.rb
- code/rack_dispatcher.rb
- code/traffic_light.rb
- source/*/dispatcher.rb
- source/*/rack_dispatcher.rb
- source/server/traffic_light.rb

Lint/ShadowingOuterLocalVariable:
Exclude:
Expand All @@ -36,22 +34,21 @@ Lint/ShadowingOuterLocalVariable:
# I often give an inline expression a name for readability
Lint/UselessAssignment:
Exclude:
- code/**/*
- source/**/*
- test/**/*

Lint/UselessMethodDefinition:
Exclude:
- code/empty_binding.rb
- source/server/empty_binding.rb

Metrics/AbcSize:
Exclude:
- test/**/*
- code/runner.rb
- code/dispatcher.rb
- code/context.rb
- code/capture3_with_timeout.rb
- client/code/dispatcher.rb
- client/code/demo.rb
- source/server/runner.rb
- source/*/dispatcher.rb
- source/server/context.rb
- source/server/capture3_with_timeout.rb
- source/client/demo.rb

Metrics/BlockLength:
Exclude:
Expand All @@ -60,38 +57,36 @@ Metrics/BlockLength:
Metrics/ClassLength:
Exclude:
- test/**/*
- code/runner.rb
- client/code/demo.rb
- source/server/runner.rb
- source/client/demo.rb

Metrics/CyclomaticComplexity:
Exclude:
- client/code/dispatcher.rb
- code/context.rb
- code/dispatcher.rb
- source/*/dispatcher.rb
- source/server/context.rb
- test/id58_test_base.rb

Metrics/MethodLength:
Exclude:
- test/**/*
- code/traffic_light.rb
- code/tagged_image_name.rb
- code/runner.rb
- code/puller.rb
- code/files_delta.rb
- code/externals/bash_sheller.rb
- code/dispatcher.rb
- code/capture3_with_timeout.rb
- client/code/dispatcher.rb
- client/code/demo.rb
- code/home_files.rb
- source/server/traffic_light.rb
- source/server/tagged_image_name.rb
- source/server/runner.rb
- source/server/puller.rb
- source/server/files_delta.rb
- source/server/externals/bash_sheller.rb
- source/*/dispatcher.rb
- source/server/capture3_with_timeout.rb
- source/client/demo.rb
- source/server/home_files.rb

Metrics/ParameterLists:
Exclude:
- code/runner.rb
- source/server/runner.rb

Metrics/PerceivedComplexity:
Exclude:
- code/context.rb
- source/server/context.rb

Naming/VariableNumber:
Exclude:
Expand All @@ -105,8 +100,7 @@ Style/ClassVars:

Style/Documentation:
Exclude:
- code/**/*
- client/code/**/*
- source/*/**/*
- test/**/*

Style/FormatStringToken:
Expand All @@ -115,8 +109,8 @@ Style/FormatStringToken:

Style/FrozenStringLiteralComment:
Exclude:
- code/gnu_zip.rb
- code/tarfile_writer.rb
- source/server/gnu_zip.rb
- source/server/tarfile_writer.rb
- test/test_base.rb

Style/MissingRespondToMissing:
Expand All @@ -125,7 +119,7 @@ Style/MissingRespondToMissing:

Style/RedundantInitialize:
Exclude:
- code/prober.rb
- source/server/prober.rb

Style/StringConcatenation:
Exclude:
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@

:+1::tada: Thanks for thinking about contributing! :tada::+1:

There is a cyber-dojo [Project Board](https://github.com/orgs/cyber-dojo/projects/3/views/1)
There is a central [CONTRIBUTING.md](https://github.com/cyber-dojo/cyber-dojo/blob/master/CONTRIBUTING.md)
There is a cyber-dojo [Project Board](https://github.com/orgs/cyber-dojo/projects/3/views/1)
13 changes: 4 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
ARG BASE_IMAGE=cyberdojo/docker-base:43587ec
FROM ${BASE_IMAGE}
# ARGs are reset after FROM See https://github.com/moby/moby/issues/34129
ARG BASE_IMAGE
ENV BASE_IMAGE=${BASE_IMAGE}

FROM cyberdojo/docker-base:9f558cc
LABEL [email protected]

RUN gem install --no-document 'concurrent-ruby'

WORKDIR /runner
COPY . .
COPY source/server/ .

ARG COMMIT_SHA
ENV SHA=${COMMIT_SHA}

USER root
HEALTHCHECK --interval=1s --timeout=1s --retries=5 --start-period=5s CMD /runner/code/config/healthcheck.sh
HEALTHCHECK --interval=1s --timeout=1s --retries=5 --start-period=5s CMD /runner/config/healthcheck.sh
ENTRYPOINT ["/sbin/tini", "-g", "--"]
CMD [ "/runner/code/config/up.sh" ]
CMD [ "/runner/config/up.sh" ]
16 changes: 7 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,22 @@
SHORT_SHA := $(shell git rev-parse HEAD | head -c7)
IMAGE_NAME := cyberdojo/runner:${SHORT_SHA}

.PHONY: image lint unit_test integration_test test demo snyk-container snyk-code

image:
${PWD}/sh/build_tag.sh

lint:
${PWD}/sh/lint.sh
${PWD}/bin/build_tag.sh

unit_test: image
${PWD}/sh/test.sh server
${PWD}/bin/test.sh server

integration_test: image
${PWD}/sh/test.sh client
${PWD}/bin/test.sh client

test: unit_test integration_test

rubocop_lint:
docker run --rm --volume "${PWD}:/app" cyberdojo/rubocop --raise-cop-error

demo:
${PWD}/sh/demo.sh
${PWD}/bin/demo.sh

snyk-container: image
snyk container test ${IMAGE_NAME} \
Expand Down
13 changes: 13 additions & 0 deletions bin/build_tag.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env bash
set -Eeu

repo_root() { git rev-parse --show-toplevel; }
export BIN_DIR="$(repo_root)/bin"

source "${BIN_DIR}/build_tagged_images.sh"
source "${BIN_DIR}/remove_old_images.sh"
source "${BIN_DIR}/echo_versioner_env_vars.sh"
export $(echo_versioner_env_vars)

remove_old_images
build_tagged_images "$@"
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
8 changes: 4 additions & 4 deletions sh/demo.sh → bin/demo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
set -Ee

repo_root() { git rev-parse --show-toplevel; }
export SH_DIR="$(repo_root)/sh"
export BIN_DIR="$(repo_root)/bin"
readonly TMP_DIR=/tmp
readonly DEMO_FILENAME="${TMP_DIR}/runner_demo.html"
readonly DEMO_URL="file://${DEMO_FILENAME}"

source "${SH_DIR}/build_tagged_images.sh"
source "${SH_DIR}/containers_up_healthy_and_clean.sh"
source "${SH_DIR}/echo_versioner_env_vars.sh"
source "${BIN_DIR}/build_tagged_images.sh"
source "${BIN_DIR}/containers_up_healthy_and_clean.sh"
source "${BIN_DIR}/echo_versioner_env_vars.sh"
export $(echo_versioner_env_vars)

run_demo() { docker exec -it test_runner_client ruby /runner/code/demo.rb > "${DEMO_FILENAME}"; }
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
18 changes: 15 additions & 3 deletions sh/setup_dependent_images.sh → bin/setup_dependent_images.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ set -Eeu

repo_root() { git rev-parse --show-toplevel; }

# - - - - - - - - - - - - - - - - - - - - - - - -
setup_dependent_images()
{
if [ "${1:-}" != server ]; then
Expand All @@ -12,7 +11,6 @@ setup_dependent_images()
remove_pulled_image
}

# - - - - - - - - - - - - - - - - - - - - - - - -
pull_dependent_images()
{
echo
Expand Down Expand Up @@ -41,13 +39,27 @@ pull_dependent_images()
| while read display_name
do
local image_name=$(echo "${JSON_DATA}" | jq --raw-output ".[\"${display_name}\"].image_name")
if [ "${image_name}" == "null" ]; then
echo "ERROR: ${display_name}"
echo "Has no entry in test/dependent_display_names.rb"
echo "This is probably because of a language and/or unit-test framework upgrade."
echo "Possible updated display_names are:"
local -r lang=$(echo "${display_name}" | awk '{print $1;}')
local -r all_names=$(echo "${JSON_DATA}" | jq 'keys')
echo "${all_names}" | while read name
do
if [[ "${name:1}" =~ ^${lang} ]]; then
echo "${name}"
fi
done
exit 42
fi
if ! echo "${IMAGE_NAMES}" | grep "${image_name}" ; then
docker pull "${image_name}"
fi
done
}

# - - - - - - - - - - - - - - - - - - - - - - - -
remove_pulled_image()
{
echo
Expand Down
24 changes: 24 additions & 0 deletions bin/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env bash
set -Eeu

repo_root() { git rev-parse --show-toplevel; }
export BIN_DIR="$(repo_root)/bin"

source "${BIN_DIR}/containers_down.sh"
source "${BIN_DIR}/containers_up_healthy_and_clean.sh"
source "${BIN_DIR}/create_test_data_manifests_file.sh"
source "${BIN_DIR}/remove_zombie_containers.sh"
source "${BIN_DIR}/setup_dependent_images.sh"
source "${BIN_DIR}/test_in_containers.sh"

source "${BIN_DIR}/echo_versioner_env_vars.sh"
export $(echo_versioner_env_vars)

remove_zombie_containers
containers_down
setup_dependent_images "$@"
create_test_data_manifests_file
server_up_healthy_and_clean
client_up_healthy_and_clean "$@"
test_in_containers "$@"
containers_down
File renamed without changes.
15 changes: 0 additions & 15 deletions build_test.sh

This file was deleted.

2 changes: 0 additions & 2 deletions client/.dockerignore

This file was deleted.

18 changes: 0 additions & 18 deletions client/Dockerfile

This file was deleted.

8 changes: 4 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ services:

client:
build:
context: client
context: source/client
args: [ COMMIT_SHA ]
image: ${CYBER_DOJO_RUNNER_CLIENT_IMAGE}:${CYBER_DOJO_RUNNER_TAG}
user: ${CYBER_DOJO_RUNNER_CLIENT_USER}
Expand All @@ -13,7 +13,7 @@ services:
env_file: [ .env ]
environment: [ CONTEXT=client, SHOW_TEST_IDS ]
read_only: true
restart: 'no'
restart: no
tmpfs: /tmp
volumes:
- ./test:/runner/test/:ro
Expand All @@ -30,7 +30,7 @@ services:
env_file: [ .env ]
environment: [ CONTEXT=server, SHOW_TEST_IDS ]
read_only: true
restart: 'no'
restart: no
tmpfs: /tmp
volumes:
- ./test:/runner/test/:ro
Expand All @@ -41,5 +41,5 @@ services:
user: nobody
env_file: [ .env ]
read_only: true
restart: "no"
restart: no
tmpfs: /tmp
Loading

0 comments on commit ec6309d

Please sign in to comment.