From 41921f915f6400e038aeab1773f0669cd7ba0e17 Mon Sep 17 00:00:00 2001 From: Eric Huang <41460388+praxxus11@users.noreply.github.com> Date: Sat, 3 Aug 2024 22:39:51 -0700 Subject: [PATCH 1/5] add nginx --- .github/workflows/build-deploy-docker.yml | 43 +++++++++++++++++++++-- docker-compose.yml | 16 +++++++-- nginx/Dockerfile | 3 ++ nginx/gateway.conf | 17 +++++++++ 4 files changed, 73 insertions(+), 6 deletions(-) create mode 100644 nginx/Dockerfile create mode 100644 nginx/gateway.conf diff --git a/.github/workflows/build-deploy-docker.yml b/.github/workflows/build-deploy-docker.yml index 7ea031a..24efd8c 100644 --- a/.github/workflows/build-deploy-docker.yml +++ b/.github/workflows/build-deploy-docker.yml @@ -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 @@ -29,9 +47,27 @@ 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] steps: - name: Check out repo. uses: actions/checkout@v4 @@ -54,4 +90,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 \ No newline at end of file + sudo docker compose up --detach + sudo docker image prune --force \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index dc2b1c6..000dc8d 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -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 \ No newline at end of file diff --git a/nginx/Dockerfile b/nginx/Dockerfile new file mode 100644 index 0000000..4552c7f --- /dev/null +++ b/nginx/Dockerfile @@ -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 \ No newline at end of file diff --git a/nginx/gateway.conf b/nginx/gateway.conf new file mode 100644 index 0000000..8540784 --- /dev/null +++ b/nginx/gateway.conf @@ -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; + } +} From dd80ae02ce14e5a3894cf5df1bdaae31ab6e4f90 Mon Sep 17 00:00:00 2001 From: Eric Huang <41460388+praxxus11@users.noreply.github.com> Date: Sat, 3 Aug 2024 22:50:03 -0700 Subject: [PATCH 2/5] run deploy if skipped. --- .github/workflows/build-deploy-docker.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/build-deploy-docker.yml b/.github/workflows/build-deploy-docker.yml index 24efd8c..fe0353a 100644 --- a/.github/workflows/build-deploy-docker.yml +++ b/.github/workflows/build-deploy-docker.yml @@ -68,6 +68,7 @@ jobs: deploy: runs-on: ubuntu-20.04 needs: [build-gateway, build-nginx] + if: ${{ always() && !failure() && !cancelled() }} steps: - name: Check out repo. uses: actions/checkout@v4 From 36ae3309d15f48e498949490bcdf50c618ba1ec9 Mon Sep 17 00:00:00 2001 From: Eric Huang <41460388+praxxus11@users.noreply.github.com> Date: Sat, 3 Aug 2024 22:53:58 -0700 Subject: [PATCH 3/5] test filter. --- .github/workflows/build-deploy-docker.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-deploy-docker.yml b/.github/workflows/build-deploy-docker.yml index fe0353a..0c168c5 100644 --- a/.github/workflows/build-deploy-docker.yml +++ b/.github/workflows/build-deploy-docker.yml @@ -19,7 +19,7 @@ jobs: outputs: gateway: ${{ steps.paths_filter.outputs.gateway }} nginx: ${{ steps.paths_filter.outputs.nginx }} - steps: + steps: - name: Execute paths filter. uses: dorny/paths-filter@v3 id: paths_filter From 2cd8e4662c4dcb5b3f69c9931d0f4ce132cfd53d Mon Sep 17 00:00:00 2001 From: Eric Huang <41460388+praxxus11@users.noreply.github.com> Date: Sat, 3 Aug 2024 22:55:17 -0700 Subject: [PATCH 4/5] only run if prev commit changed smting --- .github/workflows/build-deploy-docker.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/build-deploy-docker.yml b/.github/workflows/build-deploy-docker.yml index 0c168c5..7eaac97 100644 --- a/.github/workflows/build-deploy-docker.yml +++ b/.github/workflows/build-deploy-docker.yml @@ -24,6 +24,7 @@ jobs: uses: dorny/paths-filter@v3 id: paths_filter with: + base: ${{ github.ref }} filters: | gateway: - "./gateway/**" From c70e2591d05e0b256927c36e7c4f94e9d1099b53 Mon Sep 17 00:00:00 2001 From: Eric Huang <41460388+praxxus11@users.noreply.github.com> Date: Sat, 3 Aug 2024 22:56:49 -0700 Subject: [PATCH 5/5] remove base filter. --- .github/workflows/build-deploy-docker.yml | 1 - gateway/server/app.py | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/build-deploy-docker.yml b/.github/workflows/build-deploy-docker.yml index 7eaac97..0c168c5 100644 --- a/.github/workflows/build-deploy-docker.yml +++ b/.github/workflows/build-deploy-docker.yml @@ -24,7 +24,6 @@ jobs: uses: dorny/paths-filter@v3 id: paths_filter with: - base: ${{ github.ref }} filters: | gateway: - "./gateway/**" diff --git a/gateway/server/app.py b/gateway/server/app.py index 8124816..16429a5 100644 --- a/gateway/server/app.py +++ b/gateway/server/app.py @@ -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():