Skip to content

Commit

Permalink
Merge pull request #170 from Northeastern-Electric-Racing/rust-rewrit…
Browse files Browse the repository at this point in the history
…e-socket
  • Loading branch information
RChandler234 authored Jul 23, 2024
2 parents 4e32b47 + c0dc29d commit 4e086ad
Show file tree
Hide file tree
Showing 49 changed files with 2,475 additions and 355 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
name: Create and publish a Docker image
name: Create and publish client docker image

on:
workflow_dispatch:
Expand Down Expand Up @@ -37,7 +37,7 @@ jobs:
id: meta
uses: docker/[email protected]
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-client
# This step uses the `docker/build-push-action` action to build the image, based on your repository's `Dockerfile`. If the build succeeds, it pushes the image to GitHub Packages.
# It uses the `context` parameter to define the build's context as the set of files located in the specified path. For more information, see "[Usage](https://github.com/docker/build-push-action#usage)" in the README of the `docker/build-push-action` repository.
# It uses the `tags` and `labels` parameters to tag and label the image with the output from the "meta" step.
Expand All @@ -48,7 +48,7 @@ jobs:
push: true
target: production
platforms: linux/arm64,linux/amd64
tags: ${{ steps.meta.outputs.tags }}-angular-client # argos-angular-client
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
# for caching
# cache-from: type=gha,scope=global
Expand All @@ -59,18 +59,4 @@ jobs:
PROD=true
BACKEND_URL=http://192.168.100.1:8000
MAP_ACCESS_TOKEN=pk.eyJ1IjoibWNrZWVwIiwiYSI6ImNscXBrcmU1ZTBscWIya284cDFyYjR3Nm8ifQ.6TQHlxhAJzptZyV-W28dnw
- name: Build and push Docker image for scylla server
uses: docker/[email protected]
with:
context: ./scylla-server
push: true
target: production
platforms: linux/arm64,linux/amd64
tags: ${{ steps.meta.outputs.tags }}-scylla-server # argos-scylla-server
labels: ${{ steps.meta.outputs.labels }}
# for caching
# cache-from: type=gha
# cache-to: type=gha,mode=max
# https://github.com/docker/build-push-action/issues/820
provenance: false
57 changes: 57 additions & 0 deletions .github/workflows/scylla-server-rust-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#
name: Create and publish scylla docker image

on:
workflow_dispatch:



# Defines two custom environment variables for the workflow. These are used for the Container registry domain, and a name for the Docker image that this workflow builds.
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

# There is a single job in this workflow. It's configured to run on the latest available version of Ubuntu.
jobs:
build-and-push-image:
runs-on: ubuntu-latest
# Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job.
permissions:
contents: read
packages: write
#
steps:
- name: Set up Docker Buildx
uses: docker/[email protected]
- name: Checkout repository
uses: actions/checkout@v4
# Uses the `docker/login-action` action to log in to the Container registry registry using the account and password that will publish the packages. Once published, the packages are scoped to the account defined here.
- name: Log in to the Container registry
uses: docker/[email protected]
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# This step uses [docker/metadata-action](https://github.com/docker/metadata-action#about) to extract tags and labels that will be applied to the specified image. The `id` "meta" allows the output of this step to be referenced in a subsequent step. The `images` value provides the base name for the tags and labels.
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/[email protected]
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-scylla
# This step uses the `docker/build-push-action` action to build the image, based on your repository's `Dockerfile`. If the build succeeds, it pushes the image to GitHub Packages.
# It uses the `context` parameter to define the build's context as the set of files located in the specified path. For more information, see "[Usage](https://github.com/docker/build-push-action#usage)" in the README of the `docker/build-push-action` repository.
# It uses the `tags` and `labels` parameters to tag and label the image with the output from the "meta" step.
- name: Build and push Docker image for scylla server rust
uses: docker/[email protected]
with:
context: ./scylla-server-rust
push: true
platforms: linux/arm64,linux/amd64
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
# for caching
# cache-from: type=gha
# cache-to: type=gha,mode=max
# https://github.com/docker/build-push-action/issues/820
provenance: false

5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,7 @@ fastlane/test_output
# After new code Injection tools there's a generated folder /iOSInjectionProject
# https://github.com/johnno1962/injectionforxcode

iOSInjectionProject/
iOSInjectionProject/

# user compose override
compose.override.yml
51 changes: 34 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,34 +17,51 @@ Once you've sucessfully setup Scylla and the Client, you can either run them sep

## Production

### Running the Project in Prod Mode

There is a `docker-compose-dev.yml` file for a dev which varies from the router deployment:
The base docker compose (`compose.yml`) contains some important features to note. However, it is useless standalone. Please read the profile customization selection below before using the base compose.
- It matches the number of CPUs as the router to roughly simulate router CPU (your CPU is still faster)
- You must build it locally first!
- It does not persist the database between `down` commands
- It persists the database between `down` commands via a volume called `argos_db-data`. Delete it with `docker volume rm argos_db-data` to start with a new database next `up`.
- It weighs the CPU usage of siren higher, so it is prioritized in CPU starvation scenarios.
- It limits memory according to the capacity of the router.


### Customizing runtime profiles of the project via docker compose

This project uses docker compose overrides to secify configurations. Therefore there are multiple "profiles" to choose from when running in production, and there are some profiles for development testing. Also, there are fragment files for siren and client in `siren-base` and `angular-client` respectively, as they are services only used in certain cases. These profiles are specified via the command line on top of the base `compose.yml` file as follows.

```
docker compose -f compose.yml -f <override_file_name> <your command here>
```

Additionally if you need to create your own options, you can create a `compose.override.yml` file in this directory and specify what settings should be changed, which is ignored by git. If you think the override would become useful, document it here and name it `compose.<name>.yml`. Here is the current list of overrides, designed so only one is used at any given time:

- `scylla-dev`*: Testing the client and interactions of scylla (scylla prod, siren local, client pt local)
- `client-dev`*: Testing the client development using the scylla mock data mode (scylla mock, client pt local)
- `router`: For production deployment to the base gateway node (scylla prod, siren local, client pt 192.168.100.1)
- `tpu`: Production deployment to the TPU on the car (no client, no siren, scylla pt siren external)

Note that both compose files limit memory to the same amount. However, the disk I/O of the router is **much** slower than yours.
***Note that since client settings are changed via rebuild, overrides with a * must be rebuilt via `docker compose -f compose.yml -f compose.<override>.yml build client`. Further, a build should be done when reverting to profiles without stars. **

This will build the docker images that will be run:
Examples:

`docker-compose -f ./docker-compose-dev.yml build`
Router deploy and send to background: `docker compose -f compose.yml -f compose.router.yml up -d`

This will start the containers and output all the outputs from both of them to the terminal. If the container is not already an image through docker-compose build, it will attempt to pull the images from docker hub.
### Build and deploy

`docker-compose up`
Using the above profiles, one can `build` the app. Then, with correct permissions, you can `push` the app then `pull` it elsewhere for usage. Note that you must `push` and `pull` on the same architecture, so you cannot use for example a dell laptop to build for the router! To get `push` permissions, create a PAT [here](https://github.com/settings/tokens/new?scopes=write:packages) and copy the token into this command:

If changes are made to either the client or scylla you will need to rebuild and push to docker hub then pull on the router. Contact the current Argos lead or Chief Software Engineer to get access to the docker hub.
```
sudo docker login ghcr.io -u <gh username> -p <token>
```

### Running on the Openwrt router
Now you can update the image on a remote server. Note to save time you can just specify which service to upload, like `scylla-server-rust` or `client`.
```
sudo docker compose -f compose.yml -f compose.router.yml build && sudo docker compose -f compose.yml -f compose.router.yml push
```

The `docker-compose.yml` file is made for the router. When you push a commit it automatically gets built for the router in 20-30 minutes.
To use a non-standard branch edit the docker-compose.yml file to the name of the tag specified by the name [here](https://github.com/Northeastern-Electric-Racing/Argos/pkgs/container/argos).
Then do `docker compose down` and `docker compose pull` and `docker compose up -d`.

**The database is stored in a volume called `argos_db-data`, delete the volume to start the database fresh!**
## Codegen Protobuf Types (client only)

## Codegen Protobuf Types
Server protobuf generation is automatic. See below for client protobuf generation.

##### Mac

Expand Down
17 changes: 17 additions & 0 deletions angular-client/compose.client.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
services:
client:
container_name: client
restart: unless-stopped
image: ghcr.io/northeastern-electric-racing/argos-client:rust-rewrite-socket
build:
context: .
args:
PROD: "true"
BACKEND_URL: http://192.168.100.1:8000
MAP_ACCESS_TOKEN: pk.eyJ1IjoibWNrZWVwIiwiYSI6ImNscXBrcmU1ZTBscWIya284cDFyYjR3Nm8ifQ.6TQHlxhAJzptZyV-W28dnw
target: production
dockerfile: Dockerfile
ports:
- 80:80
cpu_shares: 512
mem_limit: 1gb
14 changes: 14 additions & 0 deletions compose.client-dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
services:
scylla-server-rust:
environment:
- PROD_SIREN_HOST_URL=siren:1883
- PROD_SCYLLA=false

client:
extends:
file: ./angular-client/compose.client.yml
service: client
build:
context: ./angular-client
args:
BACKEND_URL: http://localhost:8000
16 changes: 16 additions & 0 deletions compose.router.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
services:
scylla-server-rust:
depends_on:
- siren
environment:
- PROD_SIREN_HOST_URL=siren:1883

client:
extends:
file: ./angular-client/compose.client.yml
service: client

siren:
extends:
file: ./siren-base/compose.siren.yml
service: siren
21 changes: 21 additions & 0 deletions compose.scylla-dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
services:
scylla-server-rust:
depends_on:
- siren
environment:
- PROD_SIREN_HOST_URL=siren:1883
- RUST_LOG=none,scylla_server_rust=DEBUG

client:
extends:
file: ./angular-client/compose.client.yml
service: client
build:
context: ./angular-client
args:
BACKEND_URL: http://localhost:8000

siren:
extends:
file: ./siren-base/compose.siren.yml
service: siren
6 changes: 6 additions & 0 deletions compose.tpu.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
services:
scylla-server-rust:
environment:
- PROD_SIREN_HOST_URL=host.docker.internal:1883
extra_hosts:
- "host.docker.internal:host-gateway" # for external siren
46 changes: 46 additions & 0 deletions compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
services:
odyssey-timescale:
container_name: odyssey-timescale
image: timescale/timescaledb:2.13.1-pg15
restart: unless-stopped
environment:
POSTGRES_HOST_AUTH_METHOD: trust
ports: # needs to be published for charybdis, which runs outside of docker
- 5432:5432
expose:
- 5432
volumes:
- db-data:/var/lib/postgresql/data
cpu_shares: 1024
mem_limit: 3gb
stop_grace_period: 1m

scylla-server-rust:
container_name: scylla-server-rust
image: ghcr.io/northeastern-electric-racing/argos-scylla:rust-rewrite-socket
build:
context: ./scylla-server-rust
restart: unless-stopped
ports:
- 8000:8000
depends_on:
- odyssey-timescale
environment:
- SOURCE_DATABASE_URL=postgresql://postgres:password@odyssey-timescale:5432/timescaledb
# - PROD_SIREN_HOST_URL=siren:1883
- PROD_SCYLLA=true
- RUST_LOG=none,scylla_server_rust=INFO # default log setting for docker
cpu_shares: 1024
mem_limit: 2gb
stop_grace_period: 10s
stop_signal: SIGINT
init: true
entrypoint: ["./docker_run.sh"]



volumes:
db-data:



79 changes: 0 additions & 79 deletions docker-compose-dev.yml

This file was deleted.

Loading

0 comments on commit 4e086ad

Please sign in to comment.