diff --git a/README.md b/README.md index c74ff8f..38eb9ef 100755 --- a/README.md +++ b/README.md @@ -107,6 +107,7 @@ To run the Docker version, follow these steps: and open the directory in the console. Then run `git clone https://github.com/Human-Connection/Clock-of-Change-API.git` to clone the repository to this directory. 2. Go to the newly created Clock-of-Change-API directory (`cd Clock-of-Change-API` in the console) 3. Run `docker-compose up`. This will build the Docker container on first startup and run it. This can take a while, but after some time you should see the Clock of Change ticking. +4. To create an initial API key and sample entries, run `docker-compose exec db seed.sh`. The initial API key you can use with your requests will have the value `secret`. Now the Clock of Change API server is ready for usage at [http://127.0.0.1:1337](http://127.0.0.1:1337) diff --git a/docker-compose.yml b/docker-compose.yml index 6ccb857..7c6c468 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -3,11 +3,16 @@ version: '3' services: db: image: mysql:5 + volumes: + - coc_api_dbdata:/var/lib/mysql + - ./seed.sh:/usr/local/bin/seed.sh environment: - MYSQL_ROOT_PASSWORD: 123456 + MYSQL_ROOT_PASSWORD: clockofchangepw MYSQL_DATABASE: clock_of_change + MYSQL_USER: coc + MYSQL_PASSWORD: 123456 ports: - - 3306:3306 + - 3306:3306 mailhog: container_name: mailhog @@ -21,14 +26,14 @@ services: build: context: . volumes: - - ".:/home/node/coc-api" - - "/home/node/coc-api/node_modules" + - .:/home/node/coc-api + - /home/node/coc-api/node_modules ports: - 1337:1337 environment: - MYSQL_HOST=db - MYSQL_DB=clock_of_change - - MYSQL_USER=root + - MYSQL_USER=coc - MYSQL_PASS=123456 - MAIL_HOST=mailhog - MAIL_PORT=1025 @@ -38,3 +43,6 @@ services: - db - mailhog command: bash -c "wait-on tcp:db:3306 && db-migrate up && npm run start" + +volumes: + coc_api_dbdata: diff --git a/seed.sh b/seed.sh new file mode 100644 index 0000000..85f06b4 --- /dev/null +++ b/seed.sh @@ -0,0 +1,6 @@ +#!/bin/bash +mysql --user=$MYSQL_USER --password=$MYSQL_PASSWORD $MYSQL_DATABASE << EOF +INSERT INTO \`clock_of_change\`.\`apikeys\` (\`secret\`, \`valid\`) VALUES ('secret', '1'); +INSERT INTO \`clock_of_change\`.\`entries\` (\`firstname\`, \`lastname\`, \`email\`, \`country\`, \`message\`, \`confirm_key\`, \`beta\`, \`newsletter\`, \`pax\`, \`email_confirmed\`, \`status\`) VALUES ('Pamela', 'Musterfrau', 'pamela@example.org', 'US', 'Let us change the world!', 'confirm', '1', '0', '1', '1', '1'); +INSERT INTO \`clock_of_change\`.\`entries\` (\`firstname\`, \`lastname\`, \`email\`, \`country\`, \`message\`, \`confirm_key\`, \`beta\`, \`newsletter\`, \`pax\`, \`email_confirmed\`, \`status\`) VALUES ('Max', 'Mustermann', 'max@example.org', 'DE', 'Lasst uns die Welt verbessern!', 'confirm', '0', '1', '1', '1', '1'); +EOF