From a5902f06b3327b87d24ad9c046a73e3b941aa365 Mon Sep 17 00:00:00 2001 From: Rafi Greenberg <72412693+rafi-fisker@users.noreply.github.com> Date: Fri, 5 Nov 2021 09:09:04 -0700 Subject: [PATCH] Docker-caching-and-better-slack-notifications (#102) * test docker caching and slack * try this * this _might_ do it * cleanup * just realized this is running on self-hosted, so github cache doesn't make sense * fix logging noise * cache npm modules during test * fiskerBot and icon * quotes (just in case) --- .github/workflows/deploy.yml | 79 ++++++++++++++++++++---------------- .github/workflows/test.yml | 26 +++++------- Dockerfile | 3 +- nginx.conf | 44 ++++++++++++++++---- 4 files changed, 95 insertions(+), 57 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index daa6fae..7aabcab 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -3,23 +3,24 @@ on: branches: - develop - main - - 'release/**' - - 'hotfix/**' + - "release/**" + - "hotfix/**" jobs: deploy: name: Deploy runs-on: self-hosted env: - SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} + SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_URL }} + SLACK_CHANNEL: "#cloud-builds" + SLACK_FOOTER: "Powered by :fisker:" + SLACK_USERNAME: fiskerBot + SLACK_ICON: "https://github.com/Fisker-Inc.png?size=32" TAG: ${{ github.sha }} PROJECT: ota-admin-portal steps: - - name: Slack Notify - uses: act10ns/slack@master - with: - channel: "#cloud-builds" - status: starting + - name: Slack Notification + uses: rtCamp/action-slack-notify@v2 - name: Checkout uses: actions/checkout@v2 - name: Configure AWS Credentials @@ -33,26 +34,30 @@ jobs: uses: aws-actions/amazon-ecr-login@v1 - name: Set Env run: | - case ${GITHUB_REF} in - refs/heads/develop) - ENVIRONMENT=dev;; - refs/heads/release/*) - ENVIRONMENT=stg;; - refs/heads/hotfix/*) - ENVIRONMENT=stg;; - refs/heads/main) - ENVIRONMENT=prd;; - *) - ENVIRONMENT=dev;; - esac - echo "ENVIRONMENT=${ENVIRONMENT}" >> $GITHUB_ENV - - name: Build, tag, and push image to Amazon ECR - id: build-tag-push-image - env: - REGISTRY: ${{ steps.login-ecr.outputs.registry }} - run: | - docker build --build-arg ENVIRONMENT=$ENVIRONMENT -t $REGISTRY/$PROJECT:$TAG-$ENVIRONMENT . - docker push $REGISTRY/$PROJECT:$TAG-$ENVIRONMENT + case ${GITHUB_REF} in + refs/heads/develop) + ENVIRONMENT=dev;; + refs/heads/release/*) + ENVIRONMENT=stg;; + refs/heads/hotfix/*) + ENVIRONMENT=stg;; + refs/heads/main) + ENVIRONMENT=prd;; + *) + ENVIRONMENT=dev;; + esac + echo "ENVIRONMENT=${ENVIRONMENT}" >> $GITHUB_ENV + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + - name: Build and push + uses: docker/build-push-action@v2 + with: + context: . + build-args: ENVIRONMENT=${{ env.ENVIRONMENT }} + push: true + tags: ${{ steps.login-ecr.outputs.registry }}/${{ env.PROJECT }}:${{ env.TAG}}-${{ env.ENVIRONMENT }} + cache-from: type=registry,ref=${{ steps.login-ecr.outputs.registry }}/${{ env.PROJECT }}:${{ env.TAG}}-${{ env.ENVIRONMENT }} + cache-to: type=inline - name: Deploy id: deploy env: @@ -64,9 +69,15 @@ jobs: --set image.name=$PROJECT \ --set image.tag=$TAG-$ENVIRONMENT \ --wait -i -f k8s/values-$ENVIRONMENT.yaml $PROJECT k8s/ - - uses: act10ns/slack@master - with: - channel: "#cloud-builds" - status: ${{ job.status }} - message: Successfully deployed to ${{ env.ENVIRONMENT }}! - if: always() + - name: Notify if success + uses: rtCamp/action-slack-notify@v2 + env: + MSG_MINIMAL: true + SLACK_MESSAGE: Successfully deployed to ${{ env.ENVIRONMENT }}! + if: ${{ success() }} + - name: Notify if failure + uses: rtCamp/action-slack-notify@v2 + env: + SLACK_COLOR: ${{ job.status }} + SLACK_MESSAGE: Job failed! + if: ${{ failure() }} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 4868613..6495b31 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -4,21 +4,17 @@ on: [pull_request] jobs: build: - runs-on: ubuntu-latest - strategy: - matrix: - node-version: [14.x] - steps: - - uses: actions/checkout@v2 - - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v1 - with: - node-version: ${{ matrix.node-version }} - - run: npm install - - run: npm run build --if-present - - run: npm test - env: - CI: true \ No newline at end of file + - uses: actions/checkout@v2 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v2 + with: + node-version: "14" + cache: "npm" + - run: npm install + - run: npm run build --if-present + - run: npm test + env: + CI: true diff --git a/Dockerfile b/Dockerfile index 688ae2a..36a2580 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,4 +10,5 @@ RUN npm run build:${ENVIRONMENT} FROM nginx:alpine COPY --from=builder build /usr/share/nginx/html -COPY nginx.conf /etc/nginx/conf.d/default.conf \ No newline at end of file +COPY nginx.conf /etc/nginx/nginx.conf +ENV NGINX_ENTRYPOINT_QUIET_LOGS=true \ No newline at end of file diff --git a/nginx.conf b/nginx.conf index 214fbe6..ddd55dc 100644 --- a/nginx.conf +++ b/nginx.conf @@ -1,11 +1,41 @@ -server { - listen 80; - root /usr/share/nginx/html; - include /etc/nginx/mime.types; +user nginx; +worker_processes auto; - expires 1d; +error_log /var/log/nginx/error.log warn; +pid /var/run/nginx.pid; - location / { - try_files $uri /index.html; + +events { + worker_connections 1024; +} + + +http { + include /etc/nginx/mime.types; + default_type application/octet-stream; + + log_format main '$remote_addr - $remote_user [$time_local] "$request" ' + '$status $body_bytes_sent "$http_referer" ' + '"$http_user_agent" "$http_x_forwarded_for"'; + + access_log /var/log/nginx/access.log main; + + sendfile on; + #tcp_nopush on; + + keepalive_timeout 65; + + gzip on; + + server { + listen 80; + root /usr/share/nginx/html; + include /etc/nginx/mime.types; + + expires 1d; + + location / { + try_files $uri /index.html; + } } } \ No newline at end of file