This repository has been archived by the owner on Mar 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
13 changed files
with
342 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
name: Publish Acorn image | ||
on: | ||
push: | ||
tags: | ||
- "v[0-9]*" | ||
|
||
jobs: | ||
publish: | ||
name: Publish | ||
runs-on: ubuntu-latest | ||
permissions: | ||
packages: write | ||
contents: read | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 | ||
- uses: acorn-io/actions-setup@v2 | ||
with: | ||
acorn-version: "main" | ||
- name: Login to GHCR | ||
uses: acorn-io/actions-login@v2 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
- name: Build and Publish Acorn image | ||
run: | | ||
TAG=${GITHUB_REF#refs/*/} | ||
USER=${{ github.repository_owner }} | ||
REPO=${{ github.event.repository.name }} | ||
acorn build --platform linux/amd64 --push -t ghcr.io/$USER/$REPO:$TAG . | ||
acorn build --platform linux/amd64 --push -t ghcr.io/$USER/$REPO/examples:$TAG examples |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
services: redis: { | ||
generated: job: "create" | ||
default: true | ||
} | ||
|
||
jobs: create: { | ||
image: "alpine" | ||
env: { | ||
"secret://config": "" | ||
} | ||
dirs: { | ||
"/acorn/scripts": "./scripts" | ||
} | ||
entrypoint: ["/acorn/scripts/render.sh"] | ||
} | ||
|
||
secrets: admin: { | ||
type: "generated" | ||
params: job: "create" | ||
} | ||
|
||
secrets: config: { | ||
type: "credential.acorn.io/redis" | ||
params: { | ||
instructions: localData.instructions | ||
promptOrder: ["proto", "address", "port", "adminUsername", "adminPassword", "dbName"] | ||
} | ||
data: { | ||
address: "" | ||
port: "" | ||
adminUsername: "" | ||
adminPassword: "" | ||
proto: "" | ||
dbName: "" | ||
} | ||
} | ||
|
||
localData: instructions: """ | ||
## Overview | ||
|
||
This will create the service from an existing Redis server. | ||
|
||
## Instructions | ||
|
||
fill in: | ||
|
||
- address: the address of the Redis server endpoint (redis.example.com) | ||
- port: the port of the MongoDB server (6379) | ||
- adminPassword: the main password to use to connect to the Redis server as an admin | ||
- proto: the protocol to use to connect to the Redis server. | ||
- dbName: the name of the database to use | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
# Usage | ||
|
||
This Acorn will prompt the user for the following information: | ||
|
||
* address: the address of the Redis server. (no port) | ||
* port: the port of the Redis server. | ||
* adminUsername: the username of the admin user. | ||
* adminPassword: the password of the admin user. | ||
* dbName: the name of the database to use. (comma separated) | ||
|
||
This information will be rendered into the Acorn service object, that is interchangeable with the Acorn Redis container service. | ||
|
||
It will require you to run: | ||
|
||
```bash | ||
acorn login [APP_NAME] | ||
``` | ||
|
||
To prompt you for the information. | ||
|
||
## Example using Redis Cloud service | ||
|
||
Lets walk through deploying the example application using Redis cloud to provide the Redis DB. | ||
|
||
First we need to create a Redis Cloud instance. To do this, you will need to sign in or create an account on [Redis Cloud](https://app.redislabs.com). | ||
|
||
Once you have created an account, you will need to create a subscription and a database. You should select your subscription type and Region/Cloud vendor you want to deploy to. We will use the "Fixed plan" on AWS US-EAST-2 for this example. | ||
|
||
Select the 30MB Free plan and provide a name for your subscription. Then click "Create Subscription". | ||
|
||
Now enter a DB name, and select Redis Stack. Leave the supported protocols as is. | ||
|
||
We will leave all other settings as is. | ||
|
||
Copy the default user password and save it somewhere. We will need it later. Also, make note the username is "default". | ||
|
||
Click "Activate Database". This will kick of the provisioning process in Redis Cloud. | ||
|
||
Once the green check mark is next to you DB name, you can proceed to the next step. | ||
|
||
## Deploying the example application | ||
|
||
Now that we have the Redis Cloud instance created, we can deploy the example application. | ||
|
||
Let's run the following command: | ||
|
||
```bash | ||
acorn run -n redis-example ghcr.io/acorn-io/redis-external/examples:v#.#.# | ||
``` | ||
|
||
You should see the following output: | ||
|
||
```bash | ||
? Choose an existing credential or enter a new one Enter a new credential | ||
|
||
## Overview | ||
|
||
This will create the service from an existing Redis server. | ||
|
||
## Instructions | ||
|
||
fill in: | ||
|
||
• address: the address of the Redis server endpoint (redis.example.com) | ||
• port: the port of the MongoDB server (6379) | ||
• adminPassword: the main password to use to connect to the Redis server as | ||
an admin | ||
• proto: the protocol to use to connect to the Redis server. | ||
• dbName: the name of the database to use | ||
|
||
|
||
? address **************************************************** | ||
? adminPassword ******************************** | ||
? adminUsername ******* | ||
? dbName **** | ||
? port ***** | ||
? proto | ||
STATUS: ENDPOINTS[https://redis-example-9c5326f1.upyiuu.on-acorn.io] HEALTHY[0] UPTODATE[0] "acorn login redis-example" required | ||
STATUS: ENDPOINTS[https://redis-example-9c5326f1.upyiuu.on-acorn.io] HEALTHY[0] UPTODATE[0] (container: app): waiting for service to be created [db], waiting for service to be ready [db]; (service: db): acorn [redis-example.db] is not ready | ||
STATUS: ENDPOINTS[https://redis-example-9c5326f1.upyiuu.on-acorn.io] HEALTHY[0] UPTODATE[0] (container: app): waiting for service to be created [db], waiting for service to be ready [db], waiting for service to be created [db], waiting for service to be ready [db]; (service: db): acorn [redis-example.db] is not ready, acorn [redis-example.db] is not ready; type *unstructured.Unstructured not assignable to *v1.AppInstance | ||
STATUS: ENDPOINTS[https://redis-example-9c5326f1.upyiuu.on-acorn.io] HEALTHY[0] UPTODATE[0] (container: app): waiting for service to be created [db], waiting for service to be ready [db]; (service: db): acorn [redis-example.db] is not ready; type *unstructured.Unstructured not assignable to *v1.AppInstance, [routes.go:92] type *unstructured.Unstructured not assignable to *v1.AppInstance | ||
STATUS: ENDPOINTS[https://redis-example-9c5326f1.upyiuu.on-acorn.io] HEALTHY[0] UPTODATE[0] (container: app): waiting for service to be created [db], waiting for service to be ready [db]; (service: db): acorn [redis-example.db] is not ready | ||
STATUS: ENDPOINTS[https://redis-example-9c5326f1.upyiuu.on-acorn.io] HEALTHY[0] UPTODATE[0] (container: app): waiting for service to be ready [db]; (service: db): acorn [redis-example.db] is not ready | ||
STATUS: ENDPOINTS[https://redis-example-9c5326f1.upyiuu.on-acorn.io] HEALTHY[0] UPTODATE[0] (container: app): waiting for service to be ready [db] | ||
.... | ||
|
||
┌────────────────────────────────────────────────────────────────────────────────────────────────┐ | ||
| STATUS: ENDPOINTS[https://redis-example-9c5326f1.upyiuu.on-acorn.io] HEALTHY[1] UPTODATE[1] OK | | ||
└────────────────────────────────────────────────────────────────────────────────────────────────┘ | ||
``` | ||
|
||
Where Address is the Public Endpoint from the Redis Cloud DB information page, without the Port. Everything before the `:`. | ||
|
||
The adminUsername is "default" and the adminPassword is the password you copied earlier. | ||
|
||
The port is everything after the `:` in the Public Endpoint field. | ||
|
||
The dbName is the name of the database you created in Redis Cloud. | ||
|
||
Proto is not needed for this example. | ||
|
||
### Cleaning up | ||
|
||
To clean up the example application, run the following command: | ||
|
||
```bash | ||
acorn rm -af redis-example | ||
``` | ||
|
||
You will also need to remove the `credential.acorn.io/redis` secret and admin username by running: | ||
|
||
```bash | ||
AME TYPE KEYS CREATED | ||
acorn secret | ||
config-9swg4 credential.acorn.io/redis [address adminPassword adminUsername dbName port proto] 23m ago | ||
redis-example.db.admin basic [password username] 5h30m ago | ||
.. | ||
acorn secret rm config-9swg4 | ||
acorn secret rm redis-example.db.admin | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
services: db: { | ||
image: "ghcr.io/acorn-io/redis-external:v#.#.#" | ||
} | ||
|
||
containers: app: { | ||
build: { | ||
context: "." | ||
target: "dev" | ||
} | ||
consumes: ["db"] | ||
ports: publish: "8000/http" | ||
env: { | ||
REDIS_HOST: "@{service.db.address}" | ||
REDIS_USER: "@{service.db.secrets.admin.username}" | ||
REDIS_PASS: "@{service.db.secrets.admin.password}" | ||
REDIS_PORT: "@{service.db.ports.6379}" | ||
REDIS_DB: "@{service.db.data.dbName}" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
FROM python:3.9 as base | ||
WORKDIR /app | ||
|
||
FROM base as build | ||
COPY requirements.txt requirements.txt | ||
RUN pip install --no-cache-dir --upgrade -r requirements.txt | ||
COPY . . | ||
|
||
FROM build as dev | ||
EXPOSE 8000 | ||
CMD ["uvicorn", "main:app", "--reload", "--host", "0.0.0.0", "--port", "8000", "--proxy-headers"] | ||
|
||
FROM build as production | ||
EXPOSE 8000 | ||
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"] |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import os | ||
from fastapi import FastAPI, Request | ||
from fastapi.responses import HTMLResponse | ||
from fastapi.staticfiles import StaticFiles | ||
from fastapi.templating import Jinja2Templates | ||
from redis import Redis | ||
|
||
app = FastAPI() | ||
app.mount("/static", StaticFiles(directory="static"), name="static") | ||
templates = Jinja2Templates(directory="templates") | ||
|
||
REDIS_HOST = os.environ.get("REDIS_HOST") | ||
REDIS_PASS = os.environ.get("REDIS_PASS") | ||
REDIS_USER = os.environ.get("REDIS_USER") | ||
REDIS_PORT = os.environ.get("REDIS_PORT") | ||
|
||
redis = Redis( | ||
host=REDIS_HOST, port=REDIS_PORT, password=REDIS_PASS, username=REDIS_USER | ||
) | ||
|
||
|
||
@app.get("/", response_class=HTMLResponse) | ||
async def hello(request: Request): | ||
redis.incr("hits") | ||
counter = str(redis.get("hits"), "utf-8") | ||
return templates.TemplateResponse( | ||
"index.html", {"request": request, "counter": counter} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
fastapi == 0.101.0 | ||
uvicorn[standard] == 0.23.2 | ||
redis == 5.0.1 | ||
Jinja2 == 3.1.2 |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
html, body { | ||
height: 100%; | ||
margin: 0; | ||
padding: 0; | ||
background: #483285; | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
text-align: center; | ||
color: white; | ||
font-family: Arial, sans-serif; | ||
} | ||
.content { | ||
width: 100%; | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
justify-content: center; | ||
margin: 0; | ||
padding: 0; | ||
} | ||
img { | ||
width: 100%; | ||
max-width: 100%; | ||
height: auto; | ||
margin-bottom: 20px; | ||
} | ||
.counter { | ||
font-size: 4rem; | ||
width: 100%; | ||
margin-top: 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Stylish Counter</title> | ||
<link href="/static/style.css" rel="stylesheet"> | ||
</head> | ||
<body> | ||
<div class="content"> | ||
<img src="/static/acorn.png" alt="Acorn logo" /> | ||
<div class="counter">Page views: {{counter}}</div> | ||
</div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#!/bin/sh | ||
|
||
cat > /run/secrets/output<<EOF | ||
services: redis: { | ||
address: "${address}" | ||
default: true | ||
secrets: ["admin"] | ||
ports: "6379:${port}" | ||
data: { | ||
proto: "${proto}" | ||
dbName: "${dbName}" | ||
} | ||
} | ||
secrets: admin: { | ||
type: "basic" | ||
data: { | ||
username: "${adminUsername}" | ||
password: "${adminPassword}" | ||
} | ||
} | ||
EOF |