Skip to content

Commit

Permalink
Add Cloudflare Worker scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
Phillweston committed Apr 21, 2024
1 parent 201e20a commit a780908
Show file tree
Hide file tree
Showing 5 changed files with 475 additions and 343 deletions.
45 changes: 45 additions & 0 deletions .github/workflows/worker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Deploy Worker to Cloudflare

on:
push:
branches: [ "master" ]
paths:
- 'worker/**'
- 'wrangler.toml'
pull_request:
branches: [ "master" ]
paths:
- 'worker/**'
- 'wrangler.toml'

jobs:
deploy:
runs-on: ubuntu-latest
defaults:
run:
working-directory: worker
steps:
- uses: actions/checkout@v2

- name: Install Wrangler
run: npm install -g wrangler

- name: Replace Worker Name in wrangler.toml
run: |
WORKER_NAME=${{ secrets.CLOUDFLARE_WORKER_NAME }} || "photo-editor"
if [ -z "$WORKER_NAME" ]; then
WORKER_NAME="photo-editor"
fi
sed -i "s/name = \".*\"/name = \"$WORKER_NAME\"/" ../wrangler.toml
- name: Replace Port in worker.js
run: |
WORKER_NAME=${{ secrets.CLOUDFLARE_WORKER_NAME }} || "photo-editor"
PORT=${{ secrets.SERVER_HTTP_PORT }} || "3000"
sed -i "s/__SERVER_HTTP_PORT__/$PORT/g" worker.js
- name: Publish the Worker
run: wrangler deploy --env production
env:
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
78 changes: 78 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,84 @@

This is the backend server for the PhotoEditor project. It is a RESTful API server that provides endpoints for the frontend client to interact with the database.

## Installation and Setup

### Setting Up Required Keys

1. Create a `.env` file in the root directory of the project.
2. Add the following keys to the `.env` file:

```env
PRIVKEY_PATH="your_private_key_path"
CERT_PATH="your_cert_path"
SERVER_PORT=3000
B2_ACCOUNT_ID="your_b2_account_id"
B2_APPLICATION_KEY="your_b2_application_key"
B2_BUCKET_ID="your_b2_bucket_id"
MONGODB_USERNAME="your_mongodb_username"
MONGODB_PASSWORD="your_mongodb_password"
MONGODB_PORT="your_mongodb_port"
MONGODB_DB="your_mongodb_name"
```
### Building the Docker Image
1. Clone the repository:
```bash
git clone https://github.com/BTI-US/PhotoEditor-Server
cd PhotoEditor-Server
```
2. Build the Docker image:
```bash
docker build -t photoeditor-server .
```

### Building the MongoDB Docker Image

1. Pull the MongoDB image:
```bash
docker pull mongo
```
2. Run the docker image with the necessary environment variables:
```bash
docker run --name mongodb -d -p 27000:27000 -v /root/mongodb:/data/db -e MONGO_INITDB_ROOT_USERNAME=admin -e MONGO_INITDB_ROOT_PASSWORD=password mongo

### Running the Application

Run the Docker container using the following command:
```bash
SERVER_PORT=3000 \
MONGODB_DB=userLogs \
MONGODB_PORT=27000 \
MONGODB_USERNAME=admin \
MONGODB_PASSWORD='your_mongodb_password' \
B2_ACCOUNT_ID='your_b2_account_id' \
B2_APPLICATION_KEY='your_b2_application_key' \
B2_BUCKET_ID='your_b2_bucket_id' \
CERT_PATH=/etc/ssl/certs/fullchain2.pem \
PRIVKEY_PATH=/etc/ssl/certs/privkey2.pem \
HOST_CERT_FOLDER=/etc/letsencrypt/archive/btiplatform.com \
CONTAINER_CERT_FOLDER=/etc/ssl/certs \
docker-compose up -d
```

To remove the Docker container, run:
```bash
SERVER_PORT=5000 \
MONGODB_DB=twitterLogs \
MONGODB_USERDB=twitterUsers \
MONGODB_PORT=27017 \
MONGODB_USERNAME=admin \
MONGODB_PASSWORD='your_mongodb_password' \
TWITTER_CONSUMER_KEY='your_twitter_consumer_key' \
TWITTER_CONSUMER_SECRET='your_twitter_consumer_secret' \
CERT_PATH=/etc/ssl/certs/fullchain2.pem \
PRIVKEY_PATH=/etc/ssl/certs/privkey2.pem \
HOST_CERT_FOLDER=/etc/letsencrypt/archive/btiplatform.com \
CONTAINER_CERT_FOLDER=/etc/ssl/certs \
docker-compose down
```

## Milestone

- [x] Setup the project
Expand Down
Loading

0 comments on commit a780908

Please sign in to comment.