Skip to content

Commit

Permalink
Merge pull request #2 from praxxus11/add-nginx
Browse files Browse the repository at this point in the history
Add nginx
  • Loading branch information
praxxus11 authored Aug 4, 2024
2 parents 4b01849 + c70e259 commit dd716e1
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 7 deletions.
44 changes: 41 additions & 3 deletions .github/workflows/build-deploy-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,28 @@ env:
GITLAB_REGISTRY_TOKEN: ${{ secrets.GITLAB_REGISTRY_TOKEN }}

jobs:
detect-changes:
runs-on: ubuntu-20.04
permissions:
pull-requests: read
outputs:
gateway: ${{ steps.paths_filter.outputs.gateway }}
nginx: ${{ steps.paths_filter.outputs.nginx }}
steps:
- name: Execute paths filter.
uses: dorny/paths-filter@v3
id: paths_filter
with:
filters: |
gateway:
- "./gateway/**"
nginx:
- "./nginx/**"
build-gateway:
needs: detect-changes
if: ${{ needs.detect-changes.outputs.gateway == 'true' }}
runs-on: ubuntu-20.04
steps:
- run: ls -a
- name: Check out repo.
uses: actions/checkout@v4
- name: Setup buildx
Expand All @@ -29,9 +47,28 @@ jobs:
--tag registry.gitlab.com/segmentation964330/service/gateway \
--push \
./gateway
build-nginx:
needs: detect-changes
if: ${{ needs.detect-changes.outputs.nginx == 'true' }}
runs-on: ubuntu-20.04
steps:
- name: Check out repo.
uses: actions/checkout@v4
- name: Setup buildx
run: docker buildx create --use
- name: Sign in to segmentation gitlab registry.
run: echo "$GITLAB_REGISTRY_TOKEN" | docker login registry.gitlab.com -u "$GITLAB_REGISTRY_USERNAME" --password-stdin
- name: Build nginx image.
run: |
docker buildx build \
--platform linux/arm64 \
--tag registry.gitlab.com/segmentation964330/service/nginx \
--push \
./nginx
deploy:
runs-on: ubuntu-20.04
needs: [build-gateway]
needs: [build-gateway, build-nginx]
if: ${{ always() && !failure() && !cancelled() }}
steps:
- name: Check out repo.
uses: actions/checkout@v4
Expand All @@ -54,4 +91,5 @@ jobs:
echo "$GITLAB_REGISTRY_TOKEN" | docker login registry.gitlab.com -u "$GITLAB_REGISTRY_USERNAME" --password-stdin
sudo docker compose down
sudo docker compose pull
sudo docker compose up --detach
sudo docker compose up --detach
sudo docker image prune --force
16 changes: 13 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
services:
gateway:
container_name: gateway
image: registry.gitlab.com/segmentation964330/service/gateway
build:
context: ./gateway
ports:
- "80:8000"
volumes:
- ./artifacts/images:/home/artifacts/images
- ./artifacts/logs:/home/artifacts/logs
- ./artifacts/models:/home/artifacts/models
tty: true
stdin_open: false
stdin_open: true
nginx:
container_name: nginx
image: registry.gitlab.com/segmentation964330/service/nginx
build:
context: ./nginx
ports:
- "80:80"
depends_on:
- gateway
tty: true
stdin_open: true
2 changes: 1 addition & 1 deletion gateway/server/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def gui():
@app.route("/healthcheck")
def hello_world():
logger.info("Healthcheck.")
return "hello", 200
return "Hello world!", 200

@app.route("/predict", methods=["POST"])
def predict():
Expand Down
3 changes: 3 additions & 0 deletions nginx/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM nginx:1.27.0-alpine3.19
RUN rm /etc/nginx/conf.d/default.conf
COPY ./gateway.conf /etc/nginx/conf.d
17 changes: 17 additions & 0 deletions nginx/gateway.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
upstream segmentation_gateways {
# Docker container with name gateway must be running
server gateway:8000;
}

server {
listen 80;

location / {
proxy_pass http://segmentation_gateways;

proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}

0 comments on commit dd716e1

Please sign in to comment.