Skip to content

Commit

Permalink
optimize build logic
Browse files Browse the repository at this point in the history
  • Loading branch information
tinohager committed Jul 22, 2024
1 parent 69a37fb commit f2a9402
Show file tree
Hide file tree
Showing 4 changed files with 137 additions and 14 deletions.
41 changes: 41 additions & 0 deletions .github/workflows/build-github-pages.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs

name: Node.js CI

permissions:
contents: write

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
build:

runs-on: ubuntu-latest
env:
working-directory: ./src/Frontend

steps:
- uses: actions/checkout@v4
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: 20
#cache: 'npm'
- name: Clean slate
run: npm ci
working-directory: ${{env.working-directory}}
- name: Install quasar
run: npm install -g @quasar/cli
working-directory: ${{env.working-directory}}
- name: Build
run: quasar build
working-directory: ${{env.working-directory}}
- name: Deploy 🚀
uses: JamesIves/github-pages-deploy-action@v4
with:
folder: src/Frontend/dist/spa/ # The folder the action should deploy.
57 changes: 43 additions & 14 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs

name: Node.js CI

permissions:
contents: write
name: Docker Image CI

on:
push:
branches: [ "main" ]
branches: [ main ]
pull_request:
branches: [ "main" ]
branches: [ main ]

jobs:
build:

build-spa:

runs-on: ubuntu-latest
env:
Expand All @@ -25,7 +20,6 @@ jobs:
uses: actions/setup-node@v4
with:
node-version: 20
#cache: 'npm'
- name: Clean slate
run: npm ci
working-directory: ${{env.working-directory}}
Expand All @@ -35,7 +29,42 @@ jobs:
- name: Build
run: quasar build
working-directory: ${{env.working-directory}}
- name: Deploy 🚀
uses: JamesIves/github-pages-deploy-action@v4
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
# Artifact name
name: spa
# Directory containing files to upload
path: ${{env.working-directory}}/dist/spa/
# Days before delete
retention-days: 1

build-docker-spa:

needs: [build-spa]
runs-on: ubuntu-latest

permissions:
contents: read
packages: write

steps:
- uses: actions/checkout@v4
- name: Download artifact
uses: actions/download-artifact@v4
with:
name: spa
path: spa
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v6
with:
folder: src/Frontend/dist/spa/ # The folder the action should deploy.
context: .
file: ./src/Dockerfile-Frontend
push: true
tags: ghcr.io/${{ github.repository }}/frontend:latest
7 changes: 7 additions & 0 deletions src/Dockerfile-Frontend
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM nginx:alpine

# Listen ports
EXPOSE 80

COPY src/nginx-default.conf /etc/nginx/conf.d/default.conf
COPY spa /usr/share/nginx/html
46 changes: 46 additions & 0 deletions src/nginx-default.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
server {
listen 80;
server_name localhost;

root /usr/share/nginx/html;
index index.html;

# This will enforce HTTP browsing into HTTPS and avoid ssl stripping attack
add_header Strict-Transport-Security 'max-age=31536000; includeSubDomains; preload';

# This header enables the Cross-site scripting (XSS) filter
add_header X-XSS-Protection "1; mode=block";

# X-Frame-Options is to prevent from clickJacking attack
add_header X-Frame-Options SAMEORIGIN;

# disable content-type sniffing on some browsers.
add_header X-Content-Type-Options nosniff;

location / {
add_header Cache-Control "no-store, no-cache, must-revalidate";
try_files $uri $uri/ /index.html;
}

location /css/ {
expires 365d;
add_header Cache-Control "public";
}

location /js/ {
expires 365d;
add_header Cache-Control "public";
}

location /fonts/ {
expires 365d;
add_header Cache-Control "public";
}

location ~* \.(ico|jpg|jpeg|png|gif|svg|webp)$ {
expires 365d;
etag off;
if_modified_since off;
add_header Cache-Control "public, no-transform";
}
}

0 comments on commit f2a9402

Please sign in to comment.