项目作者: floriandejonckheere

项目描述 :
Heavy Metal recommendation and discovery platform
高级语言: Ruby
项目地址: git://github.com/floriandejonckheere/headbanger.git
创建时间: 2016-01-09T12:12:52Z
项目社区:https://github.com/floriandejonckheere/headbanger

开源协议:MIT License

下载


Headbanger

Continuous Integration
Continuous Deployment

Release
Deployment

Headbanger is a music recommendation and discovery platform.

Set up

Use the bin/setup script or run the following steps manually.

Set up the PostgreSQL database:

  1. rails db:setup

Initialize database seeds:

  1. rails database:seed # Production and development seeds
  2. rails database:seed:production # Production seeds
  3. rails database:seed:development # Development seeds

Migrating

Run database migrations:

  1. rails db:migrate

Development

Use the bin/update script to update your development environment dependencies.

Useful resources:

Debugging

To debug the server component in your IDE, start the debug instead of the app container, and connect to localhost:1234.

Testing

Seed the test database before running the test suite:

  1. rails database:seed:production RAILS_ENV=test

Run the test suite:

  1. rspec

Data sources

Metal Archives

By default, an NGINX caching proxy is configured on http://web:81/.
The app server uses this as default endpoint for queries.
If you wish to override this, set at least the MA_ENDPOINT environment variable.
MA_USER and MA_PASSWORD can be set if the endpoint is protected with HTTP Basic Authentication.

MusicBrainz

By default, the app server will use the same database settings as the main PostgreSQL server.
If you wish to override this, set the MB_HOST, MB_USER, MB_PASSWORD and MB_DATABASE environment variables.
An SSH forwarding container is also available, if the database resides on another host.
In this case, set the MB_SSH_HOST environment variable and connect to the musicbrainz container.
SSH authentication is handled by the host’s SSH agent running on SSH_AUTH_SOCK.

Troubleshooting

Rebuild the search indices:

  1. rails pg_search:multisearch:rebuild[Artist]
  2. rails pg_search:multisearch:rebuild[Group]
  3. rails pg_search:multisearch:rebuild[Release]

Secrets

Repository secrets

Github secrets for continuous integration:

  • APP_EMAIL

  • MA_ENDPOINT (optional)

  • MA_ENDPOINT_USER (optional)
  • MA_ENDPOINT_PASSWORD (optional)

Github secrets for release:

Environment secrets

Github secrets for continuous deployment (process):

  • DOCKER_TOKEN (needed for Github Container Registry)

  • SWARM_SSH_HOST (user@host)

  • SWARM_SSH_KEY (private key of user, RSA format, convert OpenSSH keys by running ssh-keygen -p -m PEM -f ~/.ssh/id_rsa)
  • SWARM_SSH_HOST_KEY (public key of host)

Github secrets for continuous deployment (application):

  • SECRET_KEY_BASE

  • APP_EMAIL

  • APP_HOST

  • PG_HOST (optional)

  • PG_USER (optional)
  • PG_PASSWORD (optional)
  • PG_DATABASE (optional)

  • RAILS_APP_SENTRY_DSN

  • VUE_APP_SENTRY_DSN
  • VUE_APP_INSTANCE
  • VUE_APP_CACHE_DOMAIN

  • SMTP_HOST

  • SMTP_PORT
  • SMTP_DOMAIN
  • SMTP_USERNAME
  • SMTP_PASSWORD
  • SMTP_FROM
  • SMTP_TO (for deployment notifications)

  • MA_ENDPOINT (optional)

  • MA_ENDPOINT_USER (optional)
  • MA_ENDPOINT_PASSWORD (optional)

  • MB_HOST (optional)

  • MB_USER (optional)
  • MB_PASSWORD (optional)
  • MB_DATABASE (optional)

  • HB_DATA_EXPIRES_IN (optional)

  • HB_SYNC_LIMIT (optional)
  • HB_SYNC_INTERVAL (optional)
  • HB_RECOMMENDATION_LIMIT (optional)

Releasing

Update the changelog and bump the version using the bin/version tool.
Execute bin/version --help to see all parameters.
Create a tag for the version and push it to Github.
A Docker image will automatically be built and pushed to the registry.

  1. bin/version version 1.0.0
  2. git add lib/headbanger/version.rb web/package.json
  3. git commit -m "Bump version to v1.0.0"
  4. git tag v1.0.0
  5. git push origin master
  6. git push origin v1.0.0

Deployment

Initial deployment

  1. # SSH into the server
  2. ssh root@myserver.com
  3. # Create a user
  4. useradd -G ssh -G docker -m -s /bin/bash headbanger
  5. su - headbanger
  6. # Create SSH keypair
  7. myserver$ mkdir ~/.ssh/
  8. ssh-keygen -f ~/.ssh/headbanger-deployment-key -b 4096 -C "Headbanger deployment key"
  9. cp ~/.ssh/headbanger-deployment-key.pub ~/.ssh/authorized_keys
  10. # Initialize the database
  11. docker exec -ti `docker ps -q name=postgres_postgres` psql -U postgres -c "CREATE ROLE headbanger WITH ENCRYPTED PASSWORD 'headbanger' LOGIN;"
  12. docker exec -ti `docker ps -q name=postgres_postgres` psql -U postgres -c "CREATE DATABASE headbanger OWNER headbanger;"
  13. # Logout, but don't forget to copy over the private key, and the host public key to your local machine
  14. logout
  15. logout
  16. # Generate TLS client certificates for NGINX
  17. openssl req -nodes -new -x509 -keyout ops/client.key -out ops/client.pem

Additionally, set DEPLOY_SSH_KEY, DEPLOY_SSH_HOST and DEPLOY_SSH_USER as Github Actions secrets.

Subsequent deployments

Ensure the images have been built and are available in the container registry.
Apply your changes in ops/docker-compose.yml.
Update the production tag to the correct commit and push it to Github
The file will automatically be deployed, and the containers recreated.

  1. nano ops/docker-compose.yml
  2. git add ops/docker-compose.yml
  3. git commit -m "Update images to latest version"
  4. git tag -f production
  5. git push origin master && git push -f origin production

License

See LICENSE.md.