Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add deploy to heroku #609

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ To execute Kutt you simply have to run `docker-compose up -d` command and then t

The `docker-compose.yml` uses the official kutt docker image available on [Docker Hub](https://hub.docker.com/r/kutt/kutt).

### Heroku

[![Deploy](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy)

### Configuration

For the minimal configuration the following settings have to be changed in the `.env`-file:
Expand Down
48 changes: 48 additions & 0 deletions app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"name": "Kutt",
"description": "Free Modern URL Shortener.",
"website": "https://kutt.it",
"repository": "https://github.com/thedevs-network/kutt",
"logo": "https://kutt.it/images/logo.svg",
"success_url": "/",
"env": {
"NPM_CONFIG_PRODUCTION": {
"value": "false"
},
Comment on lines +9 to +11
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is needed for knex migrate to run properly.

https://stackoverflow.com/a/64679533/7168030

"PGSSLMODE": {
"value": "no-verify"
},
Comment on lines +12 to +14
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is needed to connect to Heroku's Postgres without modifying the js code.

https://devcenter.heroku.com/articles/connecting-heroku-postgres#connecting-in-node-js

"SITE_NAME": {
"value": "Kutt"
},
"DEFAULT_DOMAIN": {
"value": "CHANGE.herokuapp.com"
},
"JWT_SECRET": {
"generator": "secret"
},
"MAIL_HOST": {
"required": false,
"value": ""
},
"MAIL_PORT": {
"required": false,
"value": ""
},
"MAIL_USER": {
"required": false,
"value": ""
},
"MAIL_PASSWORD": {
"required": false,
"value": ""
}
Comment on lines +24 to +39
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will allow users to manually verify the user using the method mentioned in #269 (comment)

},
"formation": {
"web": {
"quantity": 1,
"size": "FREE"
}
},
"addons": [ "heroku-redis", "heroku-postgresql"]
}
2 changes: 1 addition & 1 deletion knexfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import env from "./server/env";
module.exports = {
production: {
client: "postgresql",
connection: {
connection: env.DATABASE_URL || {
host: env.DB_HOST,
database: env.DB_NAME,
user: env.DB_USER,
Expand Down
19 changes: 18 additions & 1 deletion server/env.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { cleanEnv, num, str, bool } from "envalid";
import { cleanEnv, num, str, bool, url, EnvMissingError } from "envalid";
import reporter from "envalid/src/reporter";

const env = cleanEnv(process.env, {
PORT: num({ default: 3000 }),
SITE_NAME: str({ example: "Kutt" }),
DEFAULT_DOMAIN: str({ example: "kutt.it" }),
LINK_LENGTH: num({ default: 6 }),
DATABASE_URL: url(),
DB_HOST: str({ default: "localhost" }),
DB_PORT: num({ default: 5432 }),
DB_NAME: str({ default: "postgres" }),
Expand All @@ -16,6 +18,7 @@ const env = cleanEnv(process.env, {
NEO4J_DB_URI: str({ default: "" }),
NEO4J_DB_USERNAME: str({ default: "" }),
NEO4J_DB_PASSWORD: str({ default: "" }),
REDIS_URL: url(),
REDIS_HOST: str({ default: "127.0.0.1" }),
REDIS_PORT: num({ default: 6379 }),
REDIS_PASSWORD: str({ default: "" }),
Expand All @@ -42,6 +45,20 @@ const env = cleanEnv(process.env, {
CONTACT_EMAIL: str({ default: "" }),
SENTRY_PRIVATE_DSN: str({ default: "" }),
SENTRY_PUBLIC_DSN: str({ default: "" })
}, {
reporter: ({errors, env}: {errors: { [key: string]: Error }, env: any}) => {
if (env.DATABASE_URL !== undefined) {
delete errors['DB_USER'];
delete errors['DB_PASSWORD'];
}
if (env.DB_USER !== undefined && env.DB_PASSWORD !== undefined) {
delete errors['DATABASE_URL'];
}
if (errors['REDIS_URL'] instanceof EnvMissingError) {
delete errors['REDIS_URL'];
}
reporter({errors, env});
}
});

export default env;
2 changes: 1 addition & 1 deletion server/knex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import knex from "knex";

import env from "./env";

const db = knex({
const db = knex(env.DATABASE_URL || {
client: "postgres",
connection: {
host: env.DB_HOST,
Expand Down
2 changes: 1 addition & 1 deletion server/migration/01_host.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const neo4j = NEO4J.driver(
NEO4J.auth.basic(env.NEO4J_DB_USERNAME, env.NEO4J_DB_PASSWORD)
);
// 2. Connect to Postgres database
const postgres = knex({
const postgres = knex(env.DATABASE_URL || {
client: "postgres",
connection: {
host: env.DB_HOST,
Expand Down
2 changes: 1 addition & 1 deletion server/migration/02_users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const neo4j = NEO4J.driver(
NEO4J.auth.basic(env.NEO4J_DB_USERNAME, env.NEO4J_DB_PASSWORD)
);
// 2. Connect to Postgres database
const postgres = knex({
const postgres = knex(env.DATABASE_URL || {
client: "postgres",
connection: {
host: env.DB_HOST,
Expand Down
2 changes: 1 addition & 1 deletion server/migration/03_domains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const neo4j = NEO4J.driver(
NEO4J.auth.basic(env.NEO4J_DB_USERNAME, env.NEO4J_DB_PASSWORD)
);
// 2. Connect to Postgres database
const postgres = knex({
const postgres = knex(env.DATABASE_URL || {
client: "postgres",
connection: {
host: env.DB_HOST,
Expand Down
2 changes: 1 addition & 1 deletion server/migration/04_links.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const neo4j = NEO4J.driver(
);

// 2. Connect to Postgres database
const postgres = knex({
const postgres = knex(env.DATABASE_URL || {
client: "postgres",
connection: {
host: env.DB_HOST,
Expand Down
2 changes: 1 addition & 1 deletion server/queues/queues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import path from "path";

import env from "../env";

const redis = {
const redis = env.REDIS_URL || {
port: env.REDIS_PORT,
host: env.REDIS_HOST,
...(env.REDIS_PASSWORD && { password: env.REDIS_PASSWORD })
Expand Down
1 change: 1 addition & 0 deletions server/redis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import redis from "redis";
import env from "./env";

const client = redis.createClient({
url: env.REDIS_URL,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The short-circuit syntax REDIS_URL || {} is not allowed with the @types/redis type definition.

       server/redis.ts(6,35): error TS2769: No overload matches this call.
         The last overload gave the following error.
           Argument of type 'string | { password: string; host: string; port: number; }' is not assignable to parameter of type 'ClientOpts'.
             Type 'string' has no properties in common with type 'ClientOpts'.

host: env.REDIS_HOST,
port: env.REDIS_PORT,
...(env.REDIS_PASSWORD && { password: env.REDIS_PASSWORD })
Expand Down