Skip to content

Commit

Permalink
Merge pull request #21 from amosproj/feat/xd-10
Browse files Browse the repository at this point in the history
feat: Add GitHub Pipelines (#10)
  • Loading branch information
KonsumGandalf authored Apr 27, 2024
2 parents 7c9769e + 9910b18 commit 524f880
Show file tree
Hide file tree
Showing 15 changed files with 348 additions and 65 deletions.
22 changes: 22 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Ignore files and directories generated by npm or yarn
node_modules
npm-debug.log
yarn-error.log

# Ignore build artifacts and temporary files
/dist
/tmp
/out-tsc
#/**/*.d.ts

# Ignore development-specific files
*.md
/Deliverables
/Documentation

# Ignore version control files
.git

# Ignore Docker-specific files
.dockerignore
docker-compose.yml
42 changes: 0 additions & 42 deletions .github/workflows/ci.yml

This file was deleted.

97 changes: 97 additions & 0 deletions .github/workflows/docker-build-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
name: Docker Build and Publish

on:
push:
branches:
- develop
workflow_dispatch:

env:
REGISTRY: ghcr.io
IMAGE_NAME: amosproj/amos2024ss01-xcelerator-demo-app

jobs:
setup-buildx:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v1

backend:
runs-on: ubuntu-latest
needs: setup-buildx
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 1

- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-backend
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=sha
latest
- name: Log in to registry ${{ env.REGISTRY }}
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push backend image
uses: docker/build-push-action@v5
with:
context: .
file: ./apps/backend/Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

frontend:
runs-on: ubuntu-latest
needs: setup-buildx
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 1

- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-frontend
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=sha
latest
- name: Log in to registry ${{ env.REGISTRY }}
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push frontend image
uses: docker/build-push-action@v5
with:
context: .
file: ./apps/frontend/Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
47 changes: 30 additions & 17 deletions .github/workflows/lint-test-build.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
name: Lint Test Build

on:
push:
branches:
Expand All @@ -16,23 +17,23 @@ jobs:
with:
fetch-depth: 0

- name: test
uses: pnpm/action-setup@v2
- uses: pnpm/action-setup@v2
with:
version: 8.15.1
version: 8

# Connect your workspace on nx.app and uncomment this to enable task distribution.
# The "--stop-agents-after" is optional, but allows idle agents to shut down once the "e2e-ci" targets have been requested
- run: pnpm exec nx-cloud start-ci-run --distribute-on="5 linux-medium-js" --stop-agents-after="e2e-ci"
- name: Restore cached npm dependencies
uses: actions/cache@v4
with:
path: node_modules
key: npm-dependencies-${{ hashFiles('pnpm-lock.yaml') }}

# Cache node_modules
- uses: actions/setup-node@v4
if: steps.cache.outputs.cache-hit != 'true'
with:
node-version: 22.x
cache: 'pnpm'
node-version: 20.x

- name: PNPM install based on lockfile
run: pnpm install --frozen-lockfile
- run: pnpm install --frozen-lockfile
if: steps.cache.outputs.cache-hit != 'true'

lint:
runs-on: ubuntu-latest
Expand All @@ -43,15 +44,19 @@ jobs:
with:
fetch-depth: 1

- uses: pnpm/action-setup@v2
with:
version: 8

- run: git fetch --no-tags --prune --depth=1 origin develop

- name: Cache node modules
uses: actions/cache@v4
with:
path: node_modules
key: cache-node-modules-${{ hashFiles('pnpm-lock.json') }}
key: npm-dependencies-${{ hashFiles('pnpm-lock.yaml') }}

- run: npx nx affected --target=lint --parallel=3 --base=origin/develop
- run: pnpm nx affected --target=lint --parallel=3 --configuration=ci --base=origin/develop

test:
runs-on: ubuntu-latest
Expand All @@ -62,15 +67,19 @@ jobs:
with:
fetch-depth: 1

- uses: pnpm/action-setup@v2
with:
version: 8

- run: git fetch --no-tags --prune --depth=1 origin develop

- name: Cache node modules
uses: actions/cache@v4
with:
path: node_modules
key: cache-node-modules-${{ hashFiles('pnpm-lock.json') }}
key: npm-dependencies-${{ hashFiles('pnpm-lock.yaml') }}

- run: npx nx affected --target=test --parallel=3 --configuration=ci --base=origin/develop
- run: pnpm nx affected --target=test --parallel=3 --configuration=ci --base=origin/develop

build:
runs-on: ubuntu-latest
Expand All @@ -81,12 +90,16 @@ jobs:
with:
fetch-depth: 1

- uses: pnpm/action-setup@v2
with:
version: 8

- run: git fetch --no-tags --prune --depth=1 origin develop

- name: Cache node modules
uses: actions/cache@v4
with:
path: node_modules
key: cache-node-modules-${{ hashFiles('pnpm-lock.json') }}
key: npm-dependencies-${{ hashFiles('pnpm-lock.yaml') }}

- run: npx nx affected --target=build --parallel=3 --configuration=ci --base=origin/develop
- run: pnpm nx affected --target=build --parallel=3 --configuration=ci --base=origin/develop
20 changes: 20 additions & 0 deletions .github/workflows/release-please.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Release Please

on:
push:
branches:
- develop

permissions:
contents: write
pull-requests: write

jobs:
release-please:
runs-on: ubuntu-latest
steps:
- uses: google-github-actions/release-please-action@v4
with:
release-type: node
package-name: xcelerator-demo
target-branch: main
2 changes: 1 addition & 1 deletion .node-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
22.0.0
20.12.2
37 changes: 37 additions & 0 deletions apps/backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
FROM node:20-alpine as base

ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
RUN corepack enable

WORKDIR /usr/src/app

RUN corepack prepare [email protected] --activate

FROM base as installer

COPY package.json ./
COPY pnpm-lock.yaml ./

RUN pnpm install --frozen-lockfile --prod

FROM base as builder

ENV NX_DEAMON="false"

COPY --from=installer /usr/src/app/node_modules ./node_modules

COPY . .

RUN pnpm install --frozen-lockfile
RUN pnpm nx build backend

FROM node:20-alpine as production

COPY --from=installer /usr/src/app/node_modules ./node_modules
COPY --from=builder /usr/src/app/dist/apps/backend ./dist/

EXPOSE 3000
EXPOSE 9229

CMD ["node", "./dist/main.js"]
2 changes: 0 additions & 2 deletions apps/backend/src/app/app.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import { AppService } from './app.service';

@Controller()
export class AppController {
A = 'awdawdawd';

constructor(private readonly appService: AppService) {}

@Get()
Expand Down
33 changes: 33 additions & 0 deletions apps/frontend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
FROM node:20-alpine as base

ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
RUN corepack enable

WORKDIR /usr/src/app

RUN corepack prepare [email protected] --activate

FROM base as installer

COPY package.json ./
COPY pnpm-lock.yaml ./

RUN pnpm install --frozen-lockfile

FROM base as builder

ENV NX_DEAMON="false"

COPY --from=installer /usr/src/app/node_modules ./node_modules

COPY . .

RUN pnpm nx build frontend

FROM nginx:stable-alpine as production

COPY apps/frontend/nginx.conf /etc/nginx/conf.d/default.conf
COPY --from=builder /usr/src/app/dist/apps/frontend /usr/share/nginx/html

EXPOSE 80
26 changes: 26 additions & 0 deletions apps/frontend/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Gzip Settings
gzip on;
gzip_disable “MSIE [1-6]\.(?!.*SV1)”;
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_buffers 32 16k;
gzip_http_version 1.1;
gzip_min_length 250;
gzip_types image/jpeg image/bmp image/svg+xml text/plain text/css application/json application/javascript application/x-javascript text/xml application/xml application/xml+rss text/javascript image/x-icon;

# security headers
add_header Referrer-Policy "no-referrer-when-downgrade" always;
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload" always;

server {

listen 80;
root /usr/share/nginx/html;
autoindex on;

location / {
try_files $uri $uri/ /index.html =404;
}

}
Loading

0 comments on commit 524f880

Please sign in to comment.