Skip to content

Commit

Permalink
Merge pull request #27 from RizkyRajitha/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
RizkyRajitha committed Jul 8, 2021
2 parents 75d4fb4 + 256d157 commit 0b13b3c
Show file tree
Hide file tree
Showing 49 changed files with 1,690 additions and 685 deletions.
33 changes: 29 additions & 4 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,45 @@ jobs:
with:
node-version: ${{ matrix.node-version }}

- name: Cache node modules
uses: actions/cache@v2
env:
cache-name: cache-node-modules
with:
# npm cache files are stored in `~/.npm` on Linux/macOS
path: ~/.npm
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- name: Install dependencies
run: npm install

- name: migrate database
run: node scripts/migrate.js
- name: Migrate database
run: npm run prismamigrateprod
env:
NODE_ENV: production
DBURL: "postgres://postgres:postgres@localhost:5432/postgres"
DATABASE_URL: "postgres://postgres:postgres@localhost:5432/postgres"

- name: Seed database
run: npm run seed
env:
NODE_ENV: production
DATABASE_URL: "postgres://postgres:postgres@localhost:5432/postgres"

# - name: migrate database
# run: node scripts/migrate.js
# env:
# NODE_ENV: production
# DATABASE_URL: "postgres://postgres:postgres@localhost:5432/postgres"

- name: Run the tests
run: npm run test
env:
NODE_ENV: production
DBURL: postgres://postgres:postgres@localhost:5432/postgres
DATABASE_URL: postgres://postgres:postgres@localhost:5432/postgres

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v1
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ yarn-debug.log*
yarn-error.log*

# local env files
.env
.env.local
.env.development.local
.env.test.local
Expand Down
33 changes: 32 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,27 +1,55 @@
#globle
ARG DATABASE_URL
ARG HASHSALT
ARG RAILWAY=0
# Install dependencies only when needed
FROM node:alpine AS deps
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.

ENV NEXT_TELEMETRY_DISABLED 1

RUN apk add --no-cache libc6-compat
WORKDIR /app
COPY package.json package-lock.json ./

RUN npm ci

ENV NEXT_TELEMETRY_DISABLED 1

# Rebuild the source code only when needed
FROM node:alpine AS builder

ARG DATABASE_URL
ARG RAILWAY=0

ENV DATABASE_URL=$DATABASE_URL
ENV RAILWAY=$RAILWAY

WORKDIR /app
COPY . .
COPY --from=deps /app/node_modules ./node_modules
RUN npm run prismagenerate

RUN chmod +x railwaymigrate.sh
RUN ./railwaymigrate.sh ${RAILWAY}

RUN npm run build-next

#RUN npm ci && npm run build-next
#&& yarn install --production --ignore-scripts --prefer-offline

# Production image, copy all the files and run next
FROM node:alpine AS runner

ARG DATABASE_URL
ARG HASHSALT

ENV DATABASE_URL=$DATABASE_URL
ENV HASHSALT=$HASHSALT

WORKDIR /app

ENV NODE_ENV production
ENV NEXT_TELEMETRY_DISABLED 1

RUN addgroup -g 1001 -S nodejs
RUN adduser -S nextjs -u 1001
Expand All @@ -32,6 +60,9 @@ COPY --from=builder /app/public ./public
COPY --from=builder --chown=nextjs:nodejs /app/.next ./.next
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/package.json ./package.json
COPY --from=builder /app/prisma ./prisma
COPY --from=builder /app/scripts ./scripts
#COPY --from=builder /app/node_modules/.prisma ./node_modules/.prisma

USER nextjs

Expand Down
80 changes: 57 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@

# 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)

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

<br>

[Visit Demo](http://linkindemo.vercel.app/)
<br>
[Demo Admin](http://linkindemo.vercel.app/admin)
`http://linkindemo.vercel.app/admin`
<br>

- Demo username = `admin`
- Demo password = `linkin123`
Expand All @@ -18,24 +22,28 @@

## Deploy with Vercel

[![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)
[![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)

## Deploy with Heroku

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

## Deploy with Railway

[![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)

![Screenshot_2021-05-22 LinkIn's Link tree Page](https://user-images.githubusercontent.com/38534289/119221911-4ca94f80-bb0f-11eb-94ff-31f1c3a51d06.png)

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

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

### Getting started
## Getting started

- Deploy in Vercel
- set environment variables
- `DBURL` - **Postgres** database url
- `KEY` - random secret key
- `DATABASE_URL` - **Postgres** database url
- `HASHSALT` - random secret key
- `NODE_ENV` - set NODE_ENV to `production`
- after successfully deploying visit `youdomain/admin` to view admin login
- use default login credentials
Expand All @@ -48,26 +56,41 @@

- Deploy in Heroku
- set environment variables
- `DBURL` - **Postgres** database url
- `KEY` - random secret key
- `DATABASE_URL` - **Postgres** database url
- `HASHSALT` - random secret key
- after successfully deploying visit `youdomain/admin` to view admin login
- use default login credentials
- username = `admin`
- password = `linkin123`
- after a successfull login you will be able to see above admin dashboard.
<br>

<br>
<br>

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

## Running with docker

- build the docker image using `docker build . -t linkin` command
- 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.

- build the docker image using `docker build . -t linkin` command
- 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.

### Developing locally
## Developing locally

#### Requirements

- Node.js 10.13 or newer
- Node.js 14.x or newer
- Postgresql

#### Clone and install dependencies
Expand All @@ -79,22 +102,33 @@ npm i
```

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

example
Setup local environmrnt variables in `.env`

```.env
DBURL=postgres://linkin:123@localhost:5432/linkin
KEY=123
```
example `.env` file

```
DATABASE_URL=postgres://linkin:123@localhost:5432/linkin
HASHSALT=123
```

#### Database migration

create database relations with prisma migration

**you must have Postgres database setup locally**

```bash
node scripts/migrate.js
npx prisma migrate dev
```

#### Database Seeding

Addign Initial data to the database to get you started


```bash
npm run seed
```

#### Run
Expand All @@ -107,21 +141,21 @@ npm run dev

- [Next.Js](https://nextjs.org/) .
- [Postgres](https://www.postgresql.org/) .
- [Prisma](https://www.prisma.io/) .

### Currently supported hosting in

- [Vercel](https://vercel.com/) .
- [Heroku](https://heroku.com/) .

- [railway](https://railway.app/) .

### Community

Join our discord community for questions and updates

https://discord.gg/Jsmc5Dm9wg


<!--
<!--
https://fonts.googleapis.com/css2?family=Source+Code+Pro&display=swap
https://res.cloudinary.com/dijjqfsto/image/upload/v1621257334/af1fcce7-deb9-4834-965e-4fed59ef6c08_z2l3yf.jpg
'Source Code Pro', monospace
Expand Down
20 changes: 0 additions & 20 deletions __tests__/getpagedata.test.js

This file was deleted.

10 changes: 0 additions & 10 deletions __tests__/getusers.test.js

This file was deleted.

Loading

1 comment on commit 0b13b3c

@vercel
Copy link

@vercel vercel bot commented on 0b13b3c Jul 8, 2021

Choose a reason for hiding this comment

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

Please sign in to comment.