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

feat: railway deployment guide #70

Merged
merged 5 commits into from
Jul 31, 2024
Merged
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,5 @@ documentation/docs/dist
documentation/vocs.config.ts*
graphql/node_modules
rindexer_rust_playground/generated_csv/*/*.csv
.env
!.env.example
65 changes: 64 additions & 1 deletion documentation/docs/pages/docs/deploying/railway.mdx
Original file line number Diff line number Diff line change
@@ -1 +1,64 @@
# Railway
# Railway

## One-click Deploy Example

[![Deploy on Railway](https://railway.app/button.svg)](https://railway.app/template/Rqrlcf?referralCode=eD4laT)

## Deploy an example project

https://github.com/joshstevens19/rindexer/tree/master/providers/railway

1. Clone the relevant directory

```bash
# this will clone the railway directory
mkdir rindexer-railway && cd rindexer-railway
git clone \
--depth=1 \
--no-checkout \
--filter=tree:0 \
https://github.com/joshstevens19/rindexer .
git sparse-checkout set --no-cone providers/railway .
git checkout && cp -r providers/railway/* . && rm -rf providers
```

2. Initialize a new Railway project

```bash
railway init --name rindexer-example
```

3. Create a service and link it to the project

```bash
railway up --detach
railway link --name rindexer-example --enviroment production
```

4. Create a Postgres database

```bash
railway add --database postgre-sql
```

5. Configure environment variables

```bash
railway open
```

- then open the service "Variables" tab and click on "Add Variable Reference" and select `DATABASE_URL`,
- postfix `?sslmode=diable` to the end of the value. It should look like this: `${{Postgres.DATABASE_URL}}?sslmode=disable`,
- hit "Deploy" or Shift+Enter.

6. Create a domain to access GraphQL Playground

```bash
railway domain
```

7. Redeploy the service

```bash
railway up
```
2 changes: 1 addition & 1 deletion documentation/vocs.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export default defineConfig({
{
text: 'Deploying',
items: [
{ text: 'Railway - coming soon' },
{ text: 'Railway', link: '/docs/deploying/railway' },
{ text: 'AWS - coming soon' },
{ text: 'GCP - coming soon' },
],
Expand Down
5 changes: 5 additions & 0 deletions providers/railway/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
*

!Dockerfile
!.dockerignore
!example-app
16 changes: 16 additions & 0 deletions providers/railway/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# syntax = docker/dockerfile:1.6
FROM ghcr.io/joshstevens19/rindexer:latest AS rindexer

ARG PROJECT_PATH="./example-app"

WORKDIR /usr/src/app

COPY ${PROJECT_PATH} /usr/src/app/rindexer-app

ARG PORT="3001"
ENV PORT=${PORT}

EXPOSE ${PORT}

ENTRYPOINT ["/app/rindexer"]
CMD ["start", "-p", "./rindexer-app", "all"]
64 changes: 64 additions & 0 deletions providers/railway/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Railway

## One-click Deploy Example

[![Deploy on Railway](https://railway.app/button.svg)](https://railway.app/template/Rqrlcf?referralCode=eD4laT)

## Deploy an example project

<https://github.com/joshstevens19/rindexer/tree/master/providers/railway>

1. Clone the relevant directory

```bash
# this will clone the railway directory
mkdir rindexer-railway && cd rindexer-railway
git clone \
--depth=1 \
--no-checkout \
--filter=tree:0 \
https://github.com/joshstevens19/rindexer .
git sparse-checkout set --no-cone providers/railway .
git checkout && cp -r providers/railway/* . && rm -rf providers
```

2. Initialize a new Railway project

```bash
railway init --name rindexer-example
```

3. Create a service and link it to the project

```bash
railway up --detach
railway link --name rindexer-example --enviroment production
```

4. Create a Postgres database

```bash
railway add --database postgre-sql
```

5. Configure environment variables

```bash
railway open
```

- then open the service "Variables" tab and click on "Add Variable Reference" and select `DATABASE_URL`,
- postfix `?sslmode=diable` to the end of the value. It should look like this: `${{Postgres.DATABASE_URL}}?sslmode=disable`,
- hit "Deploy" or Shift+Enter.

6. Create a domain to access GraphQL Playground

```bash
railway domain
```

7. Redeploy the service

```bash
railway up
```
Empty file added providers/railway/aws/.gitkeep
Empty file.
153 changes: 153 additions & 0 deletions providers/railway/example-app/erc20.abi.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
[
{
"constant": true,
"inputs": [],
"name": "name",
"outputs": [{ "name": "", "type": "string" }],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [
{ "name": "guy", "type": "address" },
{ "name": "wad", "type": "uint256" }
],
"name": "approve",
"outputs": [{ "name": "", "type": "bool" }],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "totalSupply",
"outputs": [{ "name": "", "type": "uint256" }],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [
{ "name": "src", "type": "address" },
{ "name": "dst", "type": "address" },
{ "name": "wad", "type": "uint256" }
],
"name": "transferFrom",
"outputs": [{ "name": "", "type": "bool" }],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": false,
"inputs": [{ "name": "wad", "type": "uint256" }],
"name": "withdraw",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "decimals",
"outputs": [{ "name": "", "type": "uint8" }],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [{ "name": "", "type": "address" }],
"name": "balanceOf",
"outputs": [{ "name": "", "type": "uint256" }],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "symbol",
"outputs": [{ "name": "", "type": "string" }],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [
{ "name": "dst", "type": "address" },
{ "name": "wad", "type": "uint256" }
],
"name": "transfer",
"outputs": [{ "name": "", "type": "bool" }],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": false,
"inputs": [],
"name": "deposit",
"outputs": [],
"payable": true,
"stateMutability": "payable",
"type": "function"
},
{
"constant": true,
"inputs": [
{ "name": "", "type": "address" },
{ "name": "", "type": "address" }
],
"name": "allowance",
"outputs": [{ "name": "", "type": "uint256" }],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{ "payable": true, "stateMutability": "payable", "type": "fallback" },
{
"anonymous": false,
"inputs": [
{ "indexed": true, "name": "src", "type": "address" },
{ "indexed": true, "name": "guy", "type": "address" },
{ "indexed": false, "name": "wad", "type": "uint256" }
],
"name": "Approval",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{ "indexed": true, "name": "src", "type": "address" },
{ "indexed": true, "name": "dst", "type": "address" },
{ "indexed": false, "name": "wad", "type": "uint256" }
],
"name": "Transfer",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{ "indexed": true, "name": "dst", "type": "address" },
{ "indexed": false, "name": "wad", "type": "uint256" }
],
"name": "Deposit",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{ "indexed": true, "name": "src", "type": "address" },
{ "indexed": false, "name": "wad", "type": "uint256" }
],
"name": "Withdrawal",
"type": "event"
}
]
22 changes: 22 additions & 0 deletions providers/railway/example-app/rindexer.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: wETHIndexer
description: My first rindexer project
repository: https://github.com/joshstevens19/rindexer
project_type: no-code
networks:
- name: sepolia
chain_id: 11155111
rpc: https://sepolia.gateway.tenderly.co
storage:
postgres:
enabled: true
contracts:
- name: SepoliaWETH
details:
- network: sepolia
address: 0x097D90c9d3E0B50Ca60e1ae45F6A81010f9FB534
abi: ./erc20.abi.json
include_events:
- Deposit
- Approval
- Transfer
- Withdrawal
12 changes: 12 additions & 0 deletions providers/railway/railway.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#: schema https://railway.app/railway.schema.json
[build]
builder = "DOCKERFILE"
buildEnvironment = "V2"
dockerfilePath = "./Dockerfile"

[deploy]
runtime = "V2"
numReplicas = 1
sleepApplication = false
restartPolicyMaxRetries = 10
restartPolicyType = "ON_FAILURE"
Loading