Skip to content

Commit 0b13b3c

Browse files
authored
Merge pull request #27 from RizkyRajitha/dev
Dev
2 parents 75d4fb4 + 256d157 commit 0b13b3c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+1690
-685
lines changed

.github/workflows/coverage.yml

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,20 +39,45 @@ jobs:
3939
with:
4040
node-version: ${{ matrix.node-version }}
4141

42+
- name: Cache node modules
43+
uses: actions/cache@v2
44+
env:
45+
cache-name: cache-node-modules
46+
with:
47+
# npm cache files are stored in `~/.npm` on Linux/macOS
48+
path: ~/.npm
49+
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
50+
restore-keys: |
51+
${{ runner.os }}-build-${{ env.cache-name }}-
52+
${{ runner.os }}-build-
53+
${{ runner.os }}-
54+
4255
- name: Install dependencies
4356
run: npm install
4457

45-
- name: migrate database
46-
run: node scripts/migrate.js
58+
- name: Migrate database
59+
run: npm run prismamigrateprod
4760
env:
4861
NODE_ENV: production
49-
DBURL: "postgres://postgres:postgres@localhost:5432/postgres"
62+
DATABASE_URL: "postgres://postgres:postgres@localhost:5432/postgres"
63+
64+
- name: Seed database
65+
run: npm run seed
66+
env:
67+
NODE_ENV: production
68+
DATABASE_URL: "postgres://postgres:postgres@localhost:5432/postgres"
69+
70+
# - name: migrate database
71+
# run: node scripts/migrate.js
72+
# env:
73+
# NODE_ENV: production
74+
# DATABASE_URL: "postgres://postgres:postgres@localhost:5432/postgres"
5075

5176
- name: Run the tests
5277
run: npm run test
5378
env:
5479
NODE_ENV: production
55-
DBURL: postgres://postgres:postgres@localhost:5432/postgres
80+
DATABASE_URL: postgres://postgres:postgres@localhost:5432/postgres
5681

5782
- name: Upload coverage to Codecov
5883
uses: codecov/codecov-action@v1

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ yarn-debug.log*
2424
yarn-error.log*
2525

2626
# local env files
27+
.env
2728
.env.local
2829
.env.development.local
2930
.env.test.local

Dockerfile

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,55 @@
1+
#globle
2+
ARG DATABASE_URL
3+
ARG HASHSALT
4+
ARG RAILWAY=0
15
# Install dependencies only when needed
26
FROM node:alpine AS deps
37
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
8+
9+
ENV NEXT_TELEMETRY_DISABLED 1
10+
411
RUN apk add --no-cache libc6-compat
512
WORKDIR /app
613
COPY package.json package-lock.json ./
14+
715
RUN npm ci
816

9-
ENV NEXT_TELEMETRY_DISABLED 1
1017

1118
# Rebuild the source code only when needed
1219
FROM node:alpine AS builder
20+
21+
ARG DATABASE_URL
22+
ARG RAILWAY=0
23+
24+
ENV DATABASE_URL=$DATABASE_URL
25+
ENV RAILWAY=$RAILWAY
26+
1327
WORKDIR /app
1428
COPY . .
1529
COPY --from=deps /app/node_modules ./node_modules
30+
RUN npm run prismagenerate
31+
32+
RUN chmod +x railwaymigrate.sh
33+
RUN ./railwaymigrate.sh ${RAILWAY}
34+
1635
RUN npm run build-next
36+
1737
#RUN npm ci && npm run build-next
1838
#&& yarn install --production --ignore-scripts --prefer-offline
1939

2040
# Production image, copy all the files and run next
2141
FROM node:alpine AS runner
42+
43+
ARG DATABASE_URL
44+
ARG HASHSALT
45+
46+
ENV DATABASE_URL=$DATABASE_URL
47+
ENV HASHSALT=$HASHSALT
48+
2249
WORKDIR /app
2350

2451
ENV NODE_ENV production
52+
ENV NEXT_TELEMETRY_DISABLED 1
2553

2654
RUN addgroup -g 1001 -S nodejs
2755
RUN adduser -S nextjs -u 1001
@@ -32,6 +60,9 @@ COPY --from=builder /app/public ./public
3260
COPY --from=builder --chown=nextjs:nodejs /app/.next ./.next
3361
COPY --from=builder /app/node_modules ./node_modules
3462
COPY --from=builder /app/package.json ./package.json
63+
COPY --from=builder /app/prisma ./prisma
64+
COPY --from=builder /app/scripts ./scripts
65+
#COPY --from=builder /app/node_modules/.prisma ./node_modules/.prisma
3566

3667
USER nextjs
3768

README.md

Lines changed: 57 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,15 @@
44

55
# Linkin · [![DeepScan grade](https://deepscan.io/api/teams/14086/projects/17178/branches/386441/badge/grade.svg)](https://deepscan.io/dashboard#view=project&tid=14086&pid=17178&bid=386441) [![codecov](https://codecov.io/gh/RizkyRajitha/linkin/branch/master/graph/badge.svg?token=DPE3YVUYUW)](https://codecov.io/gh/RizkyRajitha/linkin) ![license](https://img.shields.io/github/license/rizkyrajitha/linkin??style=plastic) ![Github Actions](https://github.com/rizkyrajitha/linkin/workflows/Code-Coverage/badge.svg)
66

7-
## Linkin is a customizable self-hosted link tree platform.
7+
## Linkin is a customizable self-hosted link tree application.
88

99
<br>
1010

1111
[Visit Demo](http://linkindemo.vercel.app/)
12+
<br>
13+
[Demo Admin](http://linkindemo.vercel.app/admin)
14+
`http://linkindemo.vercel.app/admin`
15+
<br>
1216

1317
- Demo username = `admin`
1418
- Demo password = `linkin123`
@@ -18,24 +22,28 @@
1822

1923
## Deploy with Vercel
2024

21-
[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/git/external?repository-url=https%3A%2F%2Fgithub.com%2FRizkyRajitha%2Flinkin&env=DBURL,KEY,NODE_ENV&demo-title=Linkin&demo-description=Linkin%20is%20a%20customizable%20self%20hosted%20link%20tree%20platform%20%2C%20And%20we%20are%20ready%20to%20roll)
25+
[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/git/external?repository-url=https%3A%2F%2Fgithub.com%2FRizkyRajitha%2Flinkin&env=DATABASE_URL,HASHSALT,NODE_ENV&demo-title=Linkin&demo-description=Linkin%20is%20a%20customizable%20self%20hosted%20link%20tree%application%20%2C%20And%20we%20are%20ready%20to%20roll)
2226

2327
## Deploy with Heroku
2428

2529
[![Deploy](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy?template=https://github.com/RizkyRajitha/linkin)
2630

31+
## Deploy with Railway
32+
33+
[![Deploy on Railway](https://railway.app/button.svg)](https://railway.app/new/template?template=https%3A%2F%2Fgithub.com%2FRizkyRajitha%2Flinkin&plugins=postgresql&envs=HASHSALT%2CPORT%2CRAILWAY&HASHSALTDesc=Random+secret+HASHSALT+for+JWT+and+password+encryption&PORTDesc=Exposed+Port+in+Dockerfile&RAILWAYDesc=migrate+and+seed+the+database+in+railway+.+done+in+docker+image+build+time&PORTDefault=3000&RAILWAYDefault=1)
34+
2735
![Screenshot_2021-05-22 LinkIn's Link tree Page](https://user-images.githubusercontent.com/38534289/119221911-4ca94f80-bb0f-11eb-94ff-31f1c3a51d06.png)
2836

2937
![Screenshot_2021-05-22 Linkin Dashboard](https://user-images.githubusercontent.com/38534289/119221942-7d898480-bb0f-11eb-9175-5e139fa57f0a.png)
3038

3139
![Screenshot_2021-05-22 Linkin Dashboard](https://user-images.githubusercontent.com/38534289/119221939-7c585780-bb0f-11eb-944f-514beb5573b7.png)
3240

33-
### Getting started
41+
## Getting started
3442

3543
- Deploy in Vercel
3644
- set environment variables
37-
- `DBURL` - **Postgres** database url
38-
- `KEY` - random secret key
45+
- `DATABASE_URL` - **Postgres** database url
46+
- `HASHSALT` - random secret key
3947
- `NODE_ENV` - set NODE_ENV to `production`
4048
- after successfully deploying visit `youdomain/admin` to view admin login
4149
- use default login credentials
@@ -48,26 +56,41 @@
4856

4957
- Deploy in Heroku
5058
- set environment variables
51-
- `DBURL` - **Postgres** database url
52-
- `KEY` - random secret key
59+
- `DATABASE_URL` - **Postgres** database url
60+
- `HASHSALT` - random secret key
5361
- after successfully deploying visit `youdomain/admin` to view admin login
5462
- use default login credentials
5563
- username = `admin`
5664
- password = `linkin123`
5765
- after a successfull login you will be able to see above admin dashboard.
66+
<br>
67+
68+
<br>
5869
<br>
5970

60-
### Running with docker
71+
- Deploy in Railway
72+
- set environment variables
73+
- `HASHSALT` - random secret key
74+
- `PORT` - 3000
75+
- `RAILWAY` - Set to `1` to run migrations and seeding in docker build stage . set `0` to avoid migrations and seeding in docker build stage
76+
- `DATABASE_URL` - **Postgres** database url . use this variable **if you are not using** railway postgres plugin
77+
- after successfully deploying visit `youdomain/admin` to view admin login
78+
- use default login credentials
79+
- username = `admin`
80+
- password = `linkin123`
81+
- after a successfull login you will be able to see above admin dashboard.
82+
<br>
83+
84+
## Running with docker
6185

62-
- build the docker image using `docker build . -t linkin` command
63-
- Run the docker image `docker run -d -p 3000:3000 -e DBURL='postgres://linkin:123@localhost:5432/linkin' -e KEY='123' linkin`. make sure you specified `DBURL` and `KEY` environment varaibles.
64-
86+
- build the docker image using `docker build . -t linkin` command
87+
- Run the docker image `docker run -d -p 3000:3000 -e DATABASE_URL='postgres://linkin:123@localhost:5432/linkin' -e HASHSALT='123' linkin`. make sure you specified `DATABASE_URL` and `HASHSALT` environment varaibles.
6588

66-
### Developing locally
89+
## Developing locally
6790

6891
#### Requirements
6992

70-
- Node.js 10.13 or newer
93+
- Node.js 14.x or newer
7194
- Postgresql
7295

7396
#### Clone and install dependencies
@@ -79,22 +102,33 @@ npm i
79102
```
80103

81104
<!-- Setup local environmrnt variables in [config.js](configs/config.js) -->
82-
Setup local environmrnt variables in [.env.local](./.env.local)
83105

84-
example
106+
Setup local environmrnt variables in `.env`
85107

86-
```.env
87-
DBURL=postgres://linkin:123@localhost:5432/linkin
88-
KEY=123
89-
```
108+
example `.env` file
90109

110+
```
111+
DATABASE_URL=postgres://linkin:123@localhost:5432/linkin
112+
HASHSALT=123
113+
```
91114

92115
#### Database migration
93116

117+
create database relations with prisma migration
118+
94119
**you must have Postgres database setup locally**
95120

96121
```bash
97-
node scripts/migrate.js
122+
npx prisma migrate dev
123+
```
124+
125+
#### Database Seeding
126+
127+
Addign Initial data to the database to get you started
128+
129+
130+
```bash
131+
npm run seed
98132
```
99133

100134
#### Run
@@ -107,21 +141,21 @@ npm run dev
107141

108142
- [Next.Js](https://nextjs.org/) .
109143
- [Postgres](https://www.postgresql.org/) .
144+
- [Prisma](https://www.prisma.io/) .
110145

111146
### Currently supported hosting in
112147

113148
- [Vercel](https://vercel.com/) .
114149
- [Heroku](https://heroku.com/) .
115-
150+
- [railway](https://railway.app/) .
116151

117152
### Community
118153

119154
Join our discord community for questions and updates
120155

121156
https://discord.gg/Jsmc5Dm9wg
122157

123-
124-
<!--
158+
<!--
125159
https://fonts.googleapis.com/css2?family=Source+Code+Pro&display=swap
126160
https://res.cloudinary.com/dijjqfsto/image/upload/v1621257334/af1fcce7-deb9-4834-965e-4fed59ef6c08_z2l3yf.jpg
127161
'Source Code Pro', monospace

__tests__/getpagedata.test.js

Lines changed: 0 additions & 20 deletions
This file was deleted.

__tests__/getusers.test.js

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)