Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: meta #2

Merged
merged 5 commits into from
May 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .container/healthcheck.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
curl -f http://localhost/balancer/_meta
1 change: 1 addition & 0 deletions .container/meta
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
VERSION=dev
1 change: 1 addition & 0 deletions run.sh → .container/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ if [[ -z "${BALANCER_ENV}" ]]; then
fi

echo "Starting nginx for ${BALANCER_ENV}"
cd /app/shlokas-balancer

# render template
envsubst "\$BALANCER_ENV" < ./config/nginx.conf.template > ./config/nginx.conf
Expand Down
13 changes: 11 additions & 2 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,14 @@
"shutdownAction": "stopCompose",
"overrideCommand": true,
"onCreateCommand": ".devcontainer/on_create.sh",
"workspaceFolder": "/app/shlokas-balancer"
}
"workspaceFolder": "/app/shlokas-balancer",
"customizations": {
"vscode": {
"extensions": [
"william-voyek.vscode-nginx",
"jakebathman.nginx-log-highlighter",
"raynigon.nginx-formatter"
]
}
}
}
39 changes: 39 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Build
on:
push:

env:
REGISTRY: ghcr.io
IMAGE_NAME: ghcr.io/${{ github.repository }}
IMAGE_TAG: dev-${{github.run_number}}-${{ github.sha }}


jobs:
build:
name: 🏗️ Build
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Setup Docker buildx
uses: docker/setup-buildx-action@79abd3f86f79a9d68a23c75a09a9a85889262adf

- name: Log into registry ${{ env.REGISTRY }}
uses: docker/login-action@v2.1.0
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push
uses: docker/build-push-action@v4
with:
push: true
tags: ${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }}
build-args: |
BALANCER_VERSION=${{ env.IMAGE_TAG }}
2 changes: 2 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,5 @@ jobs:
with:
push: true
tags: ${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }},${{ env.IMAGE_NAME }}:latest
build-args: |
BALANCER_VERSION=${{ env.IMAGE_TAG }}
2 changes: 1 addition & 1 deletion .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
{
"label": "Run",
"type": "shell",
"command": "./run.sh",
"command": ".container/run.sh",
"icon": {
"id": "server",
},
Expand Down
5 changes: 4 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
FROM nginx:1.23.4-alpine
LABEL org.opencontainers.image.description "Simple load balancer for the Shlokas project."
ARG BALANCER_VERSION=dev

# Copy the nginx configuration files
WORKDIR /app/shlokas-balancer
COPY . .
RUN echo "VERSION=${BALANCER_VERSION}" > .container/meta

# Run nginx
CMD ["run.sh"]
CMD ["/app/shlokas-balancer/.container/run.sh"]
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,18 @@ Nginx Load Balancer for Shlokas. This is a simple load balancer for the Shlokas

## Development

`run.sh` will start the server in development mode. This will start the server in port `80` and will redirect requests to the backend servers.
`.container/run.sh` will start the server in development mode. This will start the server in port `80` and will redirect requests to the backend servers.

### Endable HTTPS for local development

1. Add `127.0.0.1 shlokas.dev` to `/etc/hosts`:
2. Add `rootCA.rem` as trusted root certificate.
3. Copy `certs/server.csr` and `certs/server.key` to `.secrets/balancer/certs`
4. Run `BALANCER_ENV=prod run.sh`
4. Run `BALANCER_ENV=prod .container/run.sh`


## Production

1. Copy `server.csr` and `server.key` to `.secrets/balancer/certs`
2. `BALANCER_ENV=prod run.sh` will start the server in production mode.
2. `BALANCER_ENV=prod .container/run.sh` will start the server in production mode.

7 changes: 7 additions & 0 deletions config/endpoints.conf
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
location /balancer/_meta {
default_type text/plain;
access_log off;
error_log off;
alias /app/shlokas-balancer/.container/meta;
}

location / {
if ($cors_enabled) {
add_header 'Access-Control-Allow-Origin' '*';
Expand Down
1 change: 0 additions & 1 deletion config/shlokas.conf
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ map $uri $backend {
map $backend $cors_enabled {
content true;
admin true;
auth true;
totp true;
landing true;
}
Expand Down
14 changes: 10 additions & 4 deletions config/shlokas.dev.conf
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
include shlokas.conf;

log_format debug '$request -> $status';

server {
listen 80;
server_name localhost;
charset utf-8;
server_name localhost;

access_log /dev/stdout debug;
error_log /dev/stdout debug;
listen 80;
charset utf-8;


include endpoints.conf;
include endpoints.conf;
}
Loading