Skip to content

Commit

Permalink
[automated commit] Bump docs to version 0.41.2
Browse files Browse the repository at this point in the history
  • Loading branch information
leorossi authored and github-actions[bot] committed Sep 14, 2023
1 parent d8bac65 commit dd534c5
Show file tree
Hide file tree
Showing 122 changed files with 668 additions and 356 deletions.
58 changes: 0 additions & 58 deletions versioned_docs/version-0.35.5/reference/db/dashboard.md

This file was deleted.

46 changes: 0 additions & 46 deletions versioned_docs/version-0.35.5/reference/runtime/programmatic.md

This file was deleted.

110 changes: 0 additions & 110 deletions versioned_docs/version-0.35.5/reference/start/programmatic.md

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ In this tutorial we'll learn how to:

To follow along with this tutorial you'll need to have these things installed:

- [Node.js](https://nodejs.org/) >= v18.8.0 or >= v19.0.0
- [Node.js](https://nodejs.org/) >= v18.8.0 or >= v20.6.0
- [npm](https://docs.npmjs.com/cli/) v7 or later
- A code editor, for example [Visual Studio Code](https://code.visualstudio.com/)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Platformatic supports macOS, Linux and Windows ([WSL](https://docs.microsoft.com

To follow along with this guide you'll need to have these things installed:

- [Node.js](https://nodejs.org/) >= v18.8.0 or >= v19.0.0
- [Node.js](https://nodejs.org/) >= v18.8.0 or >= v20.6.0
- [npm](https://docs.npmjs.com/cli/) v7 or later
- A code editor, for example [Visual Studio Code](https://code.visualstudio.com/)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Raw SQL queries

To run raw SQL queries using plugins, use `app.platformatic.db.query` method and passe to it a sql query using the `app.platformatic.sql` method.

```js
'use strict'
module.exports = async(app, opts) => {
app.graphql.extendSchema(`
type YearlySales {
year: Int
sales: Int
}
extend type Query {
yearlySales: [YearlySales]
}
`)
app.graphql.defineResolvers({
Query: {
yearlySales: async(_, { title }) => {
const { db, sql } = app.platformatic;
const res = await db.query(sql(`
SELECT
YEAR(created_at) AS year,
SUM(amount) AS sales
FROM
orders
GROUP BY
YEAR(created_at)
`))
return res
}
}
})
}
```
99 changes: 99 additions & 0 deletions versioned_docs/version-0.41.2/guides/dockerize-platformatic-app.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import NewApiProjectInstructions from '../getting-started/new-api-project-instructions.md';

# Dockerize a Platformatic App

This guide explains how to create a new Platformatic DB app, which connects to a PostgreSQL database.

We will then create a `docker-compose.yml` file that will run both services in separate containers

## Generate a Platformatic DB App

<NewApiProjectInstructions/>

## Create Docker image for the Platformatic DB App

In this step you are going to create some files into the root project directory

- `.dockerignore` - This file tells Docker to ignore some files when copying the directory into the image filesystem

```
node_modules
.env*
```
- `start.sh` - This is our entrypoint. We will run migrations then start platformatic
```sh
#!/bin/sh

echo "Running migrations..." && \
npx platformatic db migrations apply && \
echo "Starting Platformatic App..." && \
npm start
```
:::info
Make sure you make this file executable with the command `chmod +x start.sh`
:::


- `Dockerfile` - This is the file Docker uses to create the image

```
FROM node:18-alpine
WORKDIR /usr/src/app
COPY . .
RUN npm install
COPY . .
EXPOSE 3042
CMD [ "./start.sh" ]
```

At this point you can build your Docker image with the command
```bash
$ docker build -t platformatic-app .
```

## Create Docker Compose config file

`docker-compose.yml` is the configuration file for `docker-compose` which will spin up containers for both PostgresSQL and our Platformatic App

```yml
version: "3.3"
services:
postgresql:
ports:
- "5433:5432"
image: "postgres:15-alpine"
environment:
- POSTGRES_PASSWORD=postgres
platformatic:
ports:
- "3042:3042"
image: 'platformatic-app:latest'
depends_on:
- postgresql
links:
- postgresql
environment:
PLT_SERVER_HOSTNAME: ${PLT_SERVER_HOSTNAME}
PORT: ${PORT}
PLT_SERVER_LOGGER_LEVEL: ${PLT_SERVER_LOGGER_LEVEL}
DATABASE_URL: postgres://postgres:postgres@postgresql:5432/postgres
```
A couple of things to notice:
- The Platformatic app is started only once the database container is up and running (`depends_on`).
- The Platformatic app is linked with `postgresql` service. Meaning that inside its container `ping postgresql` will be resolved with the internal ip of the database container.
- The environment is taken directly from the `.env` file created by the wizard

You can now run your containers with

```bash
$ docker-compose up # (-d if you want to send them in the background)
```

Everything should start smoothly, and you can access your app pointing your browser to `http://0.0.0.0:3042`

To stop the app you can either press `CTRL-C` if you are running them in the foreground, or, if you used the `-d` flag, run
```bash
$ docker-compose down
```

Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,16 @@ export const createMovie: Api['createMovie'] = async (request) => {

```

You can add a `--name` option to the command line to provide a custom name for the generated files.

```bash
cd rest-api-frontend/src
npx platformatic frontend --name foobar http://127.0.0.1:3042 ts
```

will generated `foobar.ts` and `foobar-types.d.ts`


## React and Vue.js components that read, create, and update an entity

You can copy/paste the following React or Vue.js components that import the code
Expand Down
Loading

0 comments on commit dd534c5

Please sign in to comment.