From 35b973aa4e9ab874ea0afae92d13ed6b0aa99b50 Mon Sep 17 00:00:00 2001 From: Janek <62665388+Janek1010@users.noreply.github.com> Date: Wed, 19 Jun 2024 14:18:42 +0200 Subject: [PATCH] 42 docker image zrobic (#91) * FEATURE: nginx z potrzbenymi rzeczami, zmiana api ze stalego na relatywne url * FEATURE: dodanie workflow an pushowanie obrazu --- .github/workflows/docker-image.yml | 30 +++++++++++++++++++ Dockerfile | 11 +++++++ angular.json | 13 ++++---- .../etc/nginx/templates/default.conf.template | 18 +++++++++++ src/app/shared/http.config.ts | 2 +- src/proxy.conf.json | 7 +++++ 6 files changed, 74 insertions(+), 7 deletions(-) create mode 100644 .github/workflows/docker-image.yml create mode 100644 Dockerfile create mode 100644 docker/etc/nginx/templates/default.conf.template create mode 100644 src/proxy.conf.json diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml new file mode 100644 index 0000000..fa34df6 --- /dev/null +++ b/.github/workflows/docker-image.yml @@ -0,0 +1,30 @@ +name: Build and Push Docker Image + +on: + push: + branches: + - main + +jobs: + build-and-push: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Log in to Docker Hub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + - name: Build and push Docker image + uses: docker/build-push-action@v4 + with: + context: . + push: true + tags: ${{ secrets.DOCKER_USERNAME }}/angular-waytogo:latest diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..42dab8a --- /dev/null +++ b/Dockerfile @@ -0,0 +1,11 @@ +FROM nginx:latest + + +ENV API_URL http://localhost:8090/api + + +ADD dist/way-to-go-front-end /usr/share/nginx/html/ + +ADD docker/etc/nginx/templates/ /etc/nginx/templates/ + +EXPOSE 80 diff --git a/angular.json b/angular.json index bc08aed..80c9f47 100644 --- a/angular.json +++ b/angular.json @@ -45,15 +45,16 @@ "budgets": [ { "type": "initial", - "maximumWarning": "500kb", - "maximumError": "1mb" + "maximumWarning": "600kb", + "maximumError": "700kb" }, { "type": "anyComponentStyle", - "maximumWarning": "2kb", - "maximumError": "4kb" + "maximumWarning": "200kb", + "maximumError": "250kb" } - ], + ] + , "outputHashing": "all" }, "development": { @@ -67,7 +68,7 @@ "serve": { "builder": "@angular-devkit/build-angular:dev-server", "options": { - + "proxyConfig": "src/proxy.conf.json" }, "configurations": { "production": { diff --git a/docker/etc/nginx/templates/default.conf.template b/docker/etc/nginx/templates/default.conf.template new file mode 100644 index 0000000..e4158da --- /dev/null +++ b/docker/etc/nginx/templates/default.conf.template @@ -0,0 +1,18 @@ +server { + listen 80; + server_name localhost; + + location /api { + proxy_pass ${API_URL}; # Use service name from Docker Compose + proxy_set_header Host $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; + } + + location / { + root /usr/share/nginx/html/browser; + index index.html; + try_files $uri $uri/ /index.html; + } +} diff --git a/src/app/shared/http.config.ts b/src/app/shared/http.config.ts index d3427d2..2f7619e 100644 --- a/src/app/shared/http.config.ts +++ b/src/app/shared/http.config.ts @@ -1,3 +1,3 @@ export const maxPageSize = 2147483647; export const defaultPageSize = 16; -export const backendUrl = 'http://localhost:8090/api/v1' +export const backendUrl = '/api/v1' diff --git a/src/proxy.conf.json b/src/proxy.conf.json new file mode 100644 index 0000000..12bff4b --- /dev/null +++ b/src/proxy.conf.json @@ -0,0 +1,7 @@ +{ + "/api": { + "target": "http://localhost:8090", + "secure": false, + "changeOrigin": true + } +}