Skip to content

Commit

Permalink
#13: Create gRPC Server (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
dylhack committed Aug 23, 2023
1 parent 66eea25 commit 9d3f38a
Show file tree
Hide file tree
Showing 109 changed files with 4,263 additions and 756 deletions.
16 changes: 14 additions & 2 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/rust
{
"name": "Cowsay Bot",
"name": "Cowsay",
"image": "mcr.microsoft.com/devcontainers/rust:1-1-bullseye",
"postCreateCommand": "bash ./cowserve/scripts/dev-init.sh",
"features": {
"ghcr.io/devcontainers/features/docker-in-docker:2": {},
"ghcr.io/dhoeric/features/act:1": {}
"ghcr.io/dhoeric/features/act:1": {},
"ghcr.io/devcontainers-contrib/features/protoc-asdf:1": {
"version": "3.20.0"
}
},
"customizations": {
"vscode": {
"extensions": [
"zxh404.vscode-proto3",
"github.vscode-github-actions"
]
}
}
}
20 changes: 14 additions & 6 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
.devcontainer/
.github/
.vscode/
docs/
*scripts/
*.gitignore
*README.md
*/target/
.env
.env.example
.devcontainer
.gitignore
README.md
Dockerfile
tmp
docs
cowparse/Cargo.lock
cowbot/tmp
cowbot/.env
cowbot/.env.example
cowserve/.env
cowserve/.env.example
12 changes: 10 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# Optional
# DEV_SERVER_ID=0
# cowserve
DATABASE_URL=postgres://postgres:postgres@postgres:5432/postgres
SERVER_PORT=5411

# cowbot
BOT_TOKEN=
SERVER_URL=http://cowserve:$SERVER_PORT
CONTACT_URL=https://discord.gg/rtyA7rEugx
# Optional (for development)
# DEV_SERVER_ID=0

Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
name: Publish Release
name: Publish Cowbot

on:
release:
types: [published]

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
IMAGE_NAME: cowsay-bot

jobs:
publish:
name: Publish Cowbot
runs-on: ubuntu-latest
strategy:
fail-fast: false
Expand Down Expand Up @@ -51,8 +52,9 @@ jobs:
- name: Build and push Docker image
uses: docker/build-push-action@v4
with:
context: .
context: ./cowbot
push: true
target: cowbot-production
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: ${{ matrix.platform }}
60 changes: 60 additions & 0 deletions .github/workflows/release_cowserve.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: Publish Cowbot

on:
release:
types: [published]

env:
REGISTRY: ghcr.io
IMAGE_NAME: cowsay-serve

jobs:
publish:
name: Publish Cowserve
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
platform:
- linux/amd64
- linux/arm/v7
- linux/arm64
permissions:
contents: read
packages: write
steps:
-
name: Checkout
uses: actions/checkout@v3
-
name: Set up QEMU
uses: docker/setup-qemu-action@v2
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

# 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/login-action@v2
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/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
# 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
uses: docker/build-push-action@v4
with:
context: ./cowserve
push: true
target: cowserve-production
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: ${{ matrix.platform }}
34 changes: 30 additions & 4 deletions .github/workflows/standards.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,37 @@ env:
CARGO_TERM_COLOR: always

jobs:
coding_standards:
cowserve_standards:
name: "Cowserve Coding Standards"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Build
- uses: actions-rust-lang/setup-rust-toolchain@v1
- uses: arduino/setup-protoc@v2
- name: Build Cowserve
working-directory: ./cowserve
run: cargo build --verbose
- name: Test
run: bash scripts/test.sh

cowbot_standards:
name: "Cowbot Coding Standards"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions-rust-lang/setup-rust-toolchain@v1
- uses: arduino/setup-protoc@v2
- name: Build Cowbot
working-directory: ./cowbot
run: cargo build --verbose

cowparse_standards:
name: "Cowparse Coding Standards"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions-rust-lang/setup-rust-toolchain@v1
- name: Build Cowparse
working-directory: ./cowparse
run: cargo build --verbose
- name: Test Cowparse
working-directory: ./cowparse
run: cargo test --all-features
6 changes: 6 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"recommendations": [
"zxh404.vscode-proto3",
"ms-vscode-remote.remote-containers"
]
}
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"rust-analyzer.showUnlinkedFileNotification": false
}
}
36 changes: 25 additions & 11 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,25 @@
FROM rust:1.71.1-slim-buster as builder

WORKDIR /opt/app

COPY . .
RUN cargo build --release

FROM builder AS production

COPY --from=builder /opt/app/target/release/cowsay-bot /usr/local/bin/cowsay-bot
CMD cowsay-bot
FROM rust:1.71.1-bookworm as base

WORKDIR /opt/cowsay
RUN apt-get update && apt-get install -y protobuf-compiler
COPY . .

FROM base AS cowbot-builder

WORKDIR /opt/cowsay/cowbot
RUN cargo build --release

FROM base AS cowserve-builder

WORKDIR /opt/cowsay/cowserve
RUN unset DATABASE_URL && cargo build --release

FROM base AS cowserve-production

COPY --from=cowserve-builder /opt/cowsay/cowserve/target/release/cowserve /usr/local/bin/cowserve
CMD cowserve

FROM base AS cowbot-production

COPY --from=cowbot-builder /opt/cowsay/cowbot/target/release/cowbot /usr/local/bin/cowbot
CMD cowbot
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<div align="middle" float="left">


<div float="left">
<a href="https://discord.com/api/oauth2/authorize?client_id=1135038990081347605&permissions=0&scope=applications.commands%20bot">
<img alt="Ferris saying Cowsay for Discord!" src="docs/readme-ferris.webp" />
</a>
Expand Down Expand Up @@ -40,6 +38,7 @@ sure to set the `DEV_SERVER_ID` in the `.env`.
**Requirements**

- [Rust](https://www.rust-lang.org/)
- [Proto Buffer](https://protobuf.dev/downloads/)

```sh
git clone https://github.com/dylhack/cowsay-bot
Expand Down
6 changes: 6 additions & 0 deletions cowbot/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
BOT_TOKEN=
DATABASE_URL=postgres://postgres:postgres@postgres:5432/postgres
SERVER_PORT=http://localhost:5411
CONTACT_URL=https://discord.gg/rtyA7rEugx
# Optional
# DEV_SERVER_ID=0
Loading

0 comments on commit 9d3f38a

Please sign in to comment.