diff --git a/base/base-development-dockerfiles.md b/base/base-development-dockerfiles.md new file mode 100644 index 000000000..21a384d1c --- /dev/null +++ b/base/base-development-dockerfiles.md @@ -0,0 +1,12 @@ +# Base development docker images + +This folder contains dockerfiles used to create and deploy images to docker hub for the development containers. + +1. `./build.sh` + + - this will create doubtfire-api:VERSION-dev and doubtfire-web:VERSION-dev images where VERSION is based on the branch name + - test locally to ensure things work as you expect + +2. `./publish.sh` + + - things should now be available for others to use diff --git a/base/build.sh b/base/build.sh new file mode 100755 index 000000000..3f966f5fc --- /dev/null +++ b/base/build.sh @@ -0,0 +1,41 @@ +#!/bin/sh + +CURRENT_BRANCH=$(git branch --show-current) + +echo "You are on branch: ${CURRENT_BRANCH}" +echo +echo "This will produce docker images with the following names" +echo " - lmsdoubtfire/doubtfire-api:${CURRENT_BRANCH}-dev" +echo " - lmsdoubtfire/doubtfire-web:${CURRENT_BRANCH}-dev" +# echo " - lmsdoubtfire/doubtfire-overseer:${CURRENT_BRANCH}-dev" +echo + +read -p "Enter to continue..." + +function build_image { + NAME=$1 + + echo "Setting up build for $NAME" + echo + + cd ../${NAME} + + docker image rm "${NAME}:${CURRENT_BRANCH}-dev" + docker image rm "lmsdoubtfire/${NAME}:${CURRENT_BRANCH}-dev" + + docker build -t "${NAME}:${CURRENT_BRANCH}-dev" . + if [ $? -ne 0 ]; then + echo "Ensure that everything builds"; + exit 1 + fi + + docker tag "${NAME}:${CURRENT_BRANCH}-dev" "lmsdoubtfire/${NAME}:${CURRENT_BRANCH}-dev" + if [ $? -ne 0 ]; then + echo "Tag failed..."; + exit 1 + fi +} + +build_image "doubtfire-api" +build_image "doubtfire-web" +# build_image "doubtfire-overseer" \ No newline at end of file diff --git a/base/publish.sh b/base/publish.sh new file mode 100755 index 000000000..7a27e080a --- /dev/null +++ b/base/publish.sh @@ -0,0 +1,34 @@ +#!/bin/sh + +CURRENT_BRANCH=$(git branch --show-current) + +echo "You are on branch: ${CURRENT_BRANCH}" +echo +echo "This will push the following images to docker hub" +echo " - lmsdoubtfire/doubtfire-api:${CURRENT_BRANCH}-dev" +echo " - lmsdoubtfire/doubtfire-web:${CURRENT_BRANCH}-dev" +echo + +read -p "Enter to continue..." + +echo "Login to docker hub" +echo + +docker login + +function push_image { + NAME=$1 + + echo "Pushing $NAME" + echo + + docker push "lmsdoubtfire/${NAME}:${CURRENT_BRANCH}-dev" + if [ $? -ne 0 ]; then + echo "Push failed"; + exit 1 + fi +} + +push_image "doubtfire-api" +push_image "doubtfire-web" +# push_image "doubtfire-overseer" \ No newline at end of file diff --git a/development/docker-compose.yml b/development/docker-compose.yml new file mode 100644 index 000000000..d91c29001 --- /dev/null +++ b/development/docker-compose.yml @@ -0,0 +1,83 @@ +version: '3' +services: + doubtfire-api: + container_name: doubtfire-api + image: lmsdoubtfire/doubtfire-api:6.0.x-dev + ports: + - "3000:3000" + volumes: + - ../doubtfire-api/:/doubtfire + - ../data/tmp:/doubtfire/tmp + - ../data/student-work:/student-work + depends_on: + - dev-db + environment: + RAILS_ENV: 'development' + + DF_STUDENT_WORK_DIR: /student-work + DF_INSTITUTION_HOST: http://localhost:3000 + DF_INSTITUTION_PRODUCT_NAME: OnTrack + + DF_SECRET_KEY_BASE: test-secret-key-test-secret-key! + DF_SECRET_KEY_ATTR: test-secret-key-test-secret-key! + DF_SECRET_KEY_DEVISE: test-secret-key-test-secret-key! + + # Authentication method - can set to AAF or ldap + DF_AUTH_METHOD: database + DF_AAF_ISSUER_URL: https://rapid.test.aaf.edu.au + DF_AAF_AUDIENCE_URL: http://localhost:3000 + DF_AAF_CALLBACK_URL: http://localhost:3000/api/auth/jwt + DF_AAF_IDENTITY_PROVIDER_URL: https://signon-uat.deakin.edu.au/idp/shibboleth + DF_AAF_UNIQUE_URL: https://rapid.test.aaf.edu.au/jwt/authnrequest/research/Ag4EJJhjf0zXHqlKvKZEbg + DF_AAF_AUTH_SIGNOUT_URL: https://sync-uat.deakin.edu.au/auth/logout + DF_SECRET_KEY_AAF: v4~LMFLzzwRGZdju\5QBa@FiHIN9 + + # Database settings - for development env + DF_DEV_DB_ADAPTER: mysql2 + DF_DEV_DB_HOST: doubtfire-dev-db + DF_DEV_DB_DATABASE: doubtfire-dev + DF_DEV_DB_USERNAME: dfire + DF_DEV_DB_PASSWORD: pwd + + # Database settings - for test env + DF_TEST_DB_ADAPTER: mysql2 + DF_TEST_DB_HOST: doubtfire-dev-db + DF_TEST_DB_DATABASE: doubtfire-dev + DF_TEST_DB_USERNAME: dfire + DF_TEST_DB_PASSWORD: pwd + + # Database settings - for test env + DF_PRODUCTION_DB_ADAPTER: mysql2 + DF_PRODUCTION_DB_HOST: doubtfire-dev-db + DF_PRODUCTION_DB_DATABASE: doubtfire-dev + DF_PRODUCTION_DB_USERNAME: dfire + DF_PRODUCTION_DB_PASSWORD: pwd + + # Overseer - disabled! + OVERSEER_ENABLED: 0 + # RABBITMQ_HOSTNAME: doubtfire-mq + # RABBITMQ_USERNAME: secure_credentials + # RABBITMQ_PASSWORD: secure_credentials + + dev-db: + container_name: doubtfire-dev-db + image: mariadb + environment: + MYSQL_ROOT_PASSWORD: db-root-password + MYSQL_DATABASE: doubtfire-dev + MYSQL_USER: dfire + MYSQL_PASSWORD: pwd + volumes: + - ../data/database:/var/lib/mysql + + doubtfire-web: + container_name: doubtfire-web + image: doubtfire-web:6.0.x-dev + command: /bin/bash -c 'npm install; npm start' + ports: + - "4200:4200" + depends_on: + - doubtfire-api + volumes: + - ../doubtfire-web:/doubtfire-web + - ../doubtfire-web/dist:/doubtfire-web/dist diff --git a/development/readme.md b/development/readme.md new file mode 100644 index 000000000..14922a2c7 --- /dev/null +++ b/development/readme.md @@ -0,0 +1,34 @@ +# Development docker files + +This folder contains dockerfiles used to create and work with Doubtfire in development. + +Get starting by doing the following: + +- When doing this for the first time. Launch a terminal in the doubtfire-api container and setup the database: + + - `docker compose run --rm doubtfire-api bash` + - `bundle exec rails db:environment:set RAILS_ENV=development` + - `bundle exec rake db:populate` + - `exit` + + Make sure you can see output that indicates the database was created, and populated with users, units, students, etc. + +- To launch and application (web and api) + + - `docker compose up` + - Wait for things to run... + - Open a web browser navigate to: + + - [http://localhost:3000/api/docs/](http://localhost:3000/api/docs/) to interact with the API + - [http://localhost:4200](http://localhost:4200) to use the web application + + - To interact with the rails console, or other rails command line applications: + + - Attach a terminal to the doubtfire-api container: `docker compose exec doubtfire-api bash` + - To run the rails console use: `bundle exec rails c` + - To run rails tests use: `bundle exec rails test` + +- Some things to know... + + - The containers link to `../data` as a volume to store database details, tmp files, and student work. + - If you do not gracefully terminal the api you may need to remove the `pid` file from the tmp folder. You can use `rm ../data/tmp/pids/server.pid` to do this.