Skip to content

Commit

Permalink
docs/deployement: initial
Browse files Browse the repository at this point in the history
  • Loading branch information
tharvik committed May 7, 2024
1 parent a0fc873 commit 0622a84
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 54 deletions.
28 changes: 28 additions & 0 deletions docs/DEPLOYEMENT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Deployment

We are maintaining two services, the [webapp](https://discolab.ai/) and the [server](https://disco-zbkj3i466a-oa.a.run.app/).
Both are automatically deployed when pushing to the main branch via [a workflow of our CI](../.github/workflows/publish-deploy.yml).

## webapp

It is first built using a classic `npm -ws run build`.
Then is gets deployed to GitHub Pages,
with a [custom domain](https://docs.github.com/en/pages/configuring-a-custom-domain-for-your-github-pages-site).

## server

First, a [container image](<https://en.wikipedia.org/wiki/Containerization_(computing)>) is built
using the repo's [Dockerfile](https://docs.docker.com/reference/dockerfile/).
It gets pushed to [GitHub Packages](https://docs.github.com/en/packages).

It is then deployed to [Google Cloud via Cloud Run](https://cloud.google.com/run).

### Google Cloud specifics

The GitHub Action runner is authenticated via a
[Direct Workload Identity Federation](https://github.com/google-github-actions/auth?tab=readme-ov-file#preferred-direct-workload-identity-federation)
to gives it the rights of a [service account](https://cloud.google.com/iam/docs/service-account-overview)
which can administrate the deployment of the images.

The image itself is proxied via a [remote Artifact Registry](https://cloud.google.com/artifact-registry/docs/repositories/remote-overview)
as Google doesn't allow to directly get it from GitHub Packages.
54 changes: 0 additions & 54 deletions server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,57 +97,3 @@ npm -w server test

> [!WARNING]
> If you are running a VPN, docker might not properly work, e.g. `http://localhost:8080/` will result in `page not found`.
### Deploying to the Cloud

#### Google App Engine

Google App Engine (GAE) creates an HTTPS certificate automatically, making this the easiest way to deploy the helper server in the Google Cloud Platform.

Since we need to install some required dependencies we deploy using Docker, we do this by choosing:

```yml
runtime: custom
```

in the `app.yaml` file.

Deployment files:

- `app.yaml` - GAE app config file.
- `Dockerfile` - Docker [commands](https://docs.docker.com/engine/reference/builder/) we specify.
- `.dockerignore` - Files to ignore while building the image, e.g. `node_modules/`.

To change the GAE app configuration, you can modify the file `app.yaml`.

> [!WARNING]
> Make sure you allocate enough memory!
Note that the size of the container can be quite large (e.g 600mb), if the alloted memory is too small then there might be 503 [errors](https://groups.google.com/g/google-appengine/c/BawYguWHq7Q) when deploying that hard tricky to debug.

To deploy the app on GAE, you can run the following command, where disco-313515 is the current PROJECT-ID:

```sh
gcloud app deploy --project=deai-313515 app.yaml --version prod
```

:exclamation: Important!
| :exclamation: This is very important |
|-----------------------------------------|
When deploying check that in the google cloud console -> app engine -> versions, that no new instance is created as this will increase the cloud costs.
This should not happen in principle due to the "--version dev" flag, it is however a good idea to check this the first time you run this command.

Some useful resources:

- [Docker sample app](https://docs.docker.com/get-started/02_our_app/)
- [Dockerfile reference](https://docs.docker.com/engine/reference/builder/#from)
- [GAE sample app](https://cloud.google.com/appengine/docs/standard/nodejs/building-app/deploying-web-service)

#### Docker

In the docker container we specify the environment and what dependencies to install. Perhaps most importantly, once this is this done, we specify:

1. npm run build
2. npm run start

The first line compiles the ts code into js, and the second one then runs the compiled code.

0 comments on commit 0622a84

Please sign in to comment.