Skip to content

Commit

Permalink
Init
Browse files Browse the repository at this point in the history
Signed-off-by: Mihovil Ilakovac <[email protected]>
  • Loading branch information
infomiho committed Oct 31, 2024
0 parents commit c8e4319
Show file tree
Hide file tree
Showing 22 changed files with 7,676 additions and 0 deletions.
107 changes: 107 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
name: "Deploy"

on:
push:
branches:
- "main"

# This will make sure that only one deployment is running at a time
concurrency:
group: deployment
cancel-in-progress: true

env:
WASP_VERSION: "0.15.1"
# Put your server app name here
SERVER_APP_NAME: "coolify-ghcr-server"
# After you know the server URL, put the URL here
SERVER_APP_URL: "https://api.miho.dev"
# Put your client app name here
CLIENT_APP_NAME: "coolify-ghcr-client"
DOCKER_REGISTRY: "ghcr.io"
DOCKER_REGISTRY_USERNAME: ${{ github.repository_owner }}
# This secret is provided by GitHub by default and is used to authenticate with the Container registry
DOCKER_REGISTRY_PASSWORD: ${{ secrets.GITHUB_TOKEN }}
WASP_TELEMETRY_DISABLED: 1

jobs:
build-and-push-images:
permissions:
contents: read
packages: write

runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ env.DOCKER_REGISTRY_USERNAME }}
password: ${{ env.DOCKER_REGISTRY_PASSWORD }}

- name: (server) Extract metadata for Docker
id: meta-server
uses: docker/metadata-action@v5
with:
images: ${{ env.DOCKER_REGISTRY }}/${{ env.DOCKER_REGISTRY_USERNAME }}/${{ env.SERVER_APP_NAME }}

- name: (client) Extract metadata for Docker
id: meta-client
uses: docker/metadata-action@v5
with:
images: ${{ env.DOCKER_REGISTRY }}/${{ env.DOCKER_REGISTRY_USERNAME }}/${{ env.CLIENT_APP_NAME }}

- name: Install Wasp
shell: bash
run: curl -sSL https://get.wasp-lang.dev/installer.sh | sh -s -- -v ${{ env.WASP_VERSION }}

- name: Build Wasp app
shell: bash
run: wasp build

- name: (client) Build
shell: bash
run: |
cd ./.wasp/build/web-app
REACT_APP_API_URL=${{ env.SERVER_APP_URL }} npm run build
- name: (client) Prepare the Dockerfile
shell: bash
run: |
cd ./.wasp/build/web-app
echo "FROM pierrezemb/gostatic" > Dockerfile
echo "CMD [\"-fallback\", \"index.html\", \"-enable-logging\"]" >> Dockerfile
echo "COPY ./build /srv/http" >> Dockerfile
- name: (server) Build and push Docker image
uses: docker/build-push-action@v6
with:
context: ./.wasp/build
file: ./.wasp/build/Dockerfile
push: true
tags: ${{ steps.meta-server.outputs.tags }}
labels: ${{ steps.meta-server.outputs.labels }}

- name: (client) Build and push Docker image
uses: docker/build-push-action@v6
with:
context: ./.wasp/build/web-app
file: ./.wasp/build/web-app/Dockerfile
push: true
tags: ${{ steps.meta-client.outputs.tags }}
labels: ${{ steps.meta-client.outputs.labels }}

# You can get the webhook URL from the Render dashboard
# Put them in the repository secrets under RENDER_CLIENT_WEBHOOK_URL and RENDER_SERVER_WEBHOOK_URL
- name: Trigger Deploy Webhooks
env:
CLIENT_COOLIFY_WEBHOOK: ${{ secrets.CLIENT_COOLIFY_WEBHOOK }}
SERVER_COOLIFY_WEBHOOK: ${{ secrets.SERVER_COOLIFY_WEBHOOK }}
COOLIFY_TOKEN: ${{ secrets.COOLIFY_TOKEN }}
run: |
curl --request GET '${{ env.CLIENT_COOLIFY_WEBHOOK }}' --header 'Authorization: Bearer ${{ env.COOLIFY_TOKEN }}'
curl --request GET '${{ env.SERVER_COOLIFY_WEBHOOK }}' --header 'Authorization: Bearer ${{ env.COOLIFY_TOKEN }}'
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/.wasp/
/.env.server
/.env.client
/node_modules
3 changes: 3 additions & 0 deletions .waspignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Ignore editor tmp files
**/*~
**/#*#
1 change: 1 addition & 0 deletions .wasproot
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
File marking the root of Wasp project.
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# A Simple ToDo App w/ Typescript & Fullstack Type Saftey ⛑

## Running it locally

1. Make sure you have the latest version of [Wasp](https://wasp-lang.dev) installed by running `curl -sSL https://get.wasp-lang.dev/installer.sh | sh` in your terminal.
2. Run `wasp new <project-name> -t todo-ts` to create a new app using this template.
3. Run `wasp db migrate-dev`
4. Run `wasp start`. This will install all dependencies and start the client and server for you :)
5. Go to `localhost:3000` in your browser (your NodeJS server will be running on port `3001`)
6. Install the Wasp extension for VSCode to get the best DX
7. Check out the docs for more info on wasp's [features](https://wasp-lang.dev/docs/language/features) and step-by-step [guides](https://wasp-lang.dev/docs)

## Deploying with Coolify

[![Deploy](https://github.com/wasp-lang/coolify-ghcr/actions/workflows/deploy.yml/badge.svg)](https://github.com/wasp-lang/coolify-ghcr/actions/workflows/deploy.yml)

This app is deployed using Coolify and Github Container Repository.

It builds the app and Docker images for the server and the client in the Github action. The images are then pushed to the Github Container Registry.

Check the action source code here: https://github.com/wasp-lang/coolify-ghcr/blob/main/.github/workflows/deploy.yml

You'll need to create 2 resources that are deploy by using a Docker image (one for the server and one for the client) with Coolify and a PostgreSQL database.

You'll need to set the following environment variables for the server:

- `DATABASE_URL` - the connection string to your PostgreSQL database
- `PORT` - the port on which the server will run (default is 3001)
- `JWT_SECRET` - secret for JWT token
- `WASP_SERVER_URL` - the URL of the server
- `WASP_WEB_CLIENT_URL` - the URL of the client
56 changes: 56 additions & 0 deletions main.wasp
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
app coolifyGhcr {
wasp: {
version: "^0.15.0"
},
title: "Using Coolify is cool",

auth: {
userEntity: User,
methods: {
usernameAndPassword: {}, // This is a very naive implementation, use 'email' in production instead
//google: {}, // https://wasp-lang.dev/docs/integrations/google
//gitHub: {}, // https://wasp-lang.dev/docs/integrations/github
//email: {} // https://wasp-lang.dev/docs/guides/email-auth
},
onAuthFailedRedirectTo: "/login",
}
}

route RootRoute { path: "/", to: MainPage }
page MainPage {
authRequired: true,
component: import { MainPage } from "@src/MainPage"
}

route LoginRoute { path: "/login", to: LoginPage }
page LoginPage {
component: import { LoginPage } from "@src/auth/LoginPage"
}

route SignupRoute { path: "/signup", to: SignupPage }
page SignupPage {
component: import { SignupPage } from "@src/auth/SignupPage"
}

query getTasks {
// We specify the JS implementation of our query (which is an async JS function)
fn: import { getTasks } from "@src/tasks/queries",
// We tell Wasp that this query is doing something with the `Task` entity. With that, Wasp will
// automatically refresh the results of this query when tasks change.
entities: [Task]
}

action createTask {
fn: import { createTask } from "@src/tasks/actions",
entities: [Task]
}

action updateTask {
fn: import { updateTask } from "@src/tasks/actions",
entities: [Task]
}

action deleteTasks {
fn: import { deleteTasks } from "@src/tasks/actions",
entities: [Task],
}
64 changes: 64 additions & 0 deletions migrations/20240826135432_inital/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
-- CreateTable
CREATE TABLE "User" (
"id" SERIAL NOT NULL,

CONSTRAINT "User_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "Task" (
"id" SERIAL NOT NULL,
"description" TEXT NOT NULL,
"isDone" BOOLEAN NOT NULL DEFAULT false,
"userId" INTEGER NOT NULL,

CONSTRAINT "Task_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "Auth" (
"id" TEXT NOT NULL,
"userId" INTEGER,

CONSTRAINT "Auth_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "AuthIdentity" (
"providerName" TEXT NOT NULL,
"providerUserId" TEXT NOT NULL,
"providerData" TEXT NOT NULL DEFAULT '{}',
"authId" TEXT NOT NULL,

CONSTRAINT "AuthIdentity_pkey" PRIMARY KEY ("providerName","providerUserId")
);

-- CreateTable
CREATE TABLE "Session" (
"id" TEXT NOT NULL,
"expiresAt" TIMESTAMP(3) NOT NULL,
"userId" TEXT NOT NULL,

CONSTRAINT "Session_pkey" PRIMARY KEY ("id")
);

-- CreateIndex
CREATE UNIQUE INDEX "Auth_userId_key" ON "Auth"("userId");

-- CreateIndex
CREATE UNIQUE INDEX "Session_id_key" ON "Session"("id");

-- CreateIndex
CREATE INDEX "Session_userId_idx" ON "Session"("userId");

-- AddForeignKey
ALTER TABLE "Task" ADD CONSTRAINT "Task_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Auth" ADD CONSTRAINT "Auth_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "AuthIdentity" ADD CONSTRAINT "AuthIdentity_authId_fkey" FOREIGN KEY ("authId") REFERENCES "Auth"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Session" ADD CONSTRAINT "Session_userId_fkey" FOREIGN KEY ("userId") REFERENCES "Auth"("id") ON DELETE CASCADE ON UPDATE CASCADE;
3 changes: 3 additions & 0 deletions migrations/migration_lock.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Please do not edit this file manually
# It should be added in your version-control system (i.e. Git)
provider = "postgresql"
Loading

0 comments on commit c8e4319

Please sign in to comment.