From 634ec15eeaee9b7d20b134ed4cec0e8eb9340e80 Mon Sep 17 00:00:00 2001 From: Oblasov Ilya Date: Wed, 31 Aug 2022 02:23:03 +0500 Subject: [PATCH] fix CI --- .github/workflows/build_and_publish.yml | 76 ++++++++++++++++++++++++- Dockerfile | 3 +- src/index.ejs | 19 +++---- src/microfrontend-layout.html | 24 +++++--- webpack.config.js | 32 ++++++----- 5 files changed, 116 insertions(+), 38 deletions(-) diff --git a/.github/workflows/build_and_publish.yml b/.github/workflows/build_and_publish.yml index 39c38c6..ab06d1c 100644 --- a/.github/workflows/build_and_publish.yml +++ b/.github/workflows/build_and_publish.yml @@ -2,14 +2,16 @@ name: Build, publish and deploy docker on: push: - branches: ['main'] + branches: ["main"] + tags: + - 'v*' env: REGISTRY: ghcr.io IMAGE_NAME: ${{ github.repository }} jobs: - build-and-push-image: + build-and-push-image-testing: name: Build and push runs-on: ubuntu-latest permissions: @@ -32,18 +34,61 @@ jobs: uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38 with: images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + tags: | + type=raw,value=test,enable=true - name: Build and push Docker image uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc with: context: . push: true + build-args: | + BUILD_MODE=development + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + + build-and-push-image-production: + name: Build and push + runs-on: ubuntu-latest + if: startsWith(github.ref, 'refs/tags/v') + permissions: + contents: read + packages: write + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Log in to the Container registry + uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + tags: | + type=ref,event=tag,enable=${{ startsWith(github.ref, 'refs/tags/v') }} + type=raw,value=latest,enable=${{ startsWith(github.ref, 'refs/tags/v') }} + type=raw,value=test,enable=true + + - name: Build and push Docker image + uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc + with: + context: . + push: true + build-args: | + BUILD_MODE=production tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} deploy-testing: name: Deploy Testing - needs: build-and-push-image + needs: build-and-push-image-testing runs-on: [self-hosted, Linux] environment: name: Testing @@ -64,3 +109,28 @@ jobs: --name ${{ env.CONTAITER_NAME }} \ --network=web \ ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:main + + deploy-production: + name: Deploy Production + needs: build-and-push-image-production + if: startsWith(github.ref, 'refs/tags/v') + runs-on: [self-hosted, Linux] + environment: + name: Production + url: https://app.profcomff.com/ + env: + CONTAITER_NAME: com_profcomff_app + permissions: + packages: read + + steps: + - name: Run docker container + run: | + docker pull ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:main + docker stop ${{ env.CONTAITER_NAME }} || true && docker rm ${{ env.CONTAITER_NAME }} || true + docker run \ + --detach \ + --restart on-failure:3 \ + --name ${{ env.CONTAITER_NAME }} \ + --network=web \ + ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:main diff --git a/Dockerfile b/Dockerfile index 28b6c5e..0b9488e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,9 +1,10 @@ FROM node:16 AS build +ARG BUILD_MODE WORKDIR /app ADD ./package.json ./package-lock.json /app/ RUN npm install ADD . /app -RUN npm run build:webpack +RUN npm run build:webpack -- --env $BUILD_MODE FROM nginx:1.21 ADD ./default.conf /etc/nginx/conf.d/default.conf diff --git a/src/index.ejs b/src/index.ejs index 016e42f..94c256b 100644 --- a/src/index.ejs +++ b/src/index.ejs @@ -10,16 +10,15 @@ - + <% if (development) { %> + + <% } %> + <% if (isLocal) { %> + + <% } %> + <% if (production) { %> + + <% } %> diff --git a/src/microfrontend-layout.html b/src/microfrontend-layout.html index 1971ee3..028c6b1 100644 --- a/src/microfrontend-layout.html +++ b/src/microfrontend-layout.html @@ -12,17 +12,23 @@ -
+
-

Вы попали на страницу, которой еще не существует в приложении =(

+

+ Вы попали на страницу, которой еще не существует в приложении =( +

-

Попробуйте вернуться назад.

+

+ Попробуйте вернуться назад. +

diff --git a/webpack.config.js b/webpack.config.js index 7b49871..a342012 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -3,8 +3,7 @@ const singleSpaDefaults = require("webpack-config-single-spa"); const HtmlWebpackPlugin = require("html-webpack-plugin"); const CopyWebpackPlugin = require("copy-webpack-plugin"); const WebpackPwaManifest = require("webpack-pwa-manifest"); -const WorkboxPlugin = require('workbox-webpack-plugin'); - +const WorkboxPlugin = require("workbox-webpack-plugin"); module.exports = (webpackConfigEnv, argv) => { const orgName = "profcomff"; @@ -23,6 +22,8 @@ module.exports = (webpackConfigEnv, argv) => { template: "src/index.ejs", templateParameters: { isLocal: webpackConfigEnv && webpackConfigEnv.isLocal, + production: webpackConfigEnv && webpackConfigEnv.production, + development: webpackConfigEnv && webpackConfigEnv.development, orgName, }, }), @@ -57,24 +58,25 @@ module.exports = (webpackConfigEnv, argv) => { ], inject: false, fingerprints: false, - ios: true + ios: true, }), new WorkboxPlugin.GenerateSW({ clientsClaim: true, skipWaiting: true, runtimeCaching: [ - { - urlPattern: /.*\.profcomff\.com/, - handler: 'StaleWhileRevalidate', - }, - { - // Cache google fonts - urlPattern: /^https:\/\/fonts\.(?:gstatic|googleapis)\.com/, - handler: 'StaleWhileRevalidate', - options: { - cacheName: 'google-fonts-webfonts' - } - }] + { + urlPattern: /.*\.profcomff\.com/, + handler: "StaleWhileRevalidate", + }, + { + // Cache google fonts + urlPattern: /^https:\/\/fonts\.(?:gstatic|googleapis)\.com/, + handler: "StaleWhileRevalidate", + options: { + cacheName: "google-fonts-webfonts", + }, + }, + ], }), ], });