From 6850c70bbf7fd42b99dd460d0efac9755462ffaf Mon Sep 17 00:00:00 2001 From: kirillesau Date: Mon, 9 Jun 2025 17:52:38 +0200 Subject: [PATCH] =?UTF-8?q?Workflow=20hinzugef=C3=BCgt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Angular app wird gebaut - Angular App wird als Image in DockerHub gepushed - Readme Anpassungen --- .dockerignore | 5 +++ .github/workflows/build-application.yml | 56 +++++++++++++++++++++++++ .vscode/extensions.json | 4 -- .vscode/launch.json | 20 --------- .vscode/tasks.json | 42 ------------------- Dockerfile | 39 +++++++++++++++++ LICENSE.txt | 21 ++++++++++ README.md | 31 ++++---------- 8 files changed, 128 insertions(+), 90 deletions(-) create mode 100644 .dockerignore create mode 100644 .github/workflows/build-application.yml delete mode 100644 .vscode/extensions.json delete mode 100644 .vscode/launch.json delete mode 100644 .vscode/tasks.json create mode 100644 Dockerfile create mode 100644 LICENSE.txt diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..685f30f --- /dev/null +++ b/.dockerignore @@ -0,0 +1,5 @@ +node_modules +dist +docker-compose*.yml +*.log +.git diff --git a/.github/workflows/build-application.yml b/.github/workflows/build-application.yml new file mode 100644 index 0000000..4cd42b4 --- /dev/null +++ b/.github/workflows/build-application.yml @@ -0,0 +1,56 @@ +name: Build and Deploy Script +on: + push: + branches: + - main + pull_request: + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout Repository + uses: actions/checkout@v4 + + - name: Adding Node.js + uses: actions/setup-node@v4 + with: + node-version: 22.16.0 + cache: 'npm' + + - name: Install Dependencies + run: npm install + + - name: Run Unit Tests + run: npm test -- --watch=false --browsers=ChromeHeadless + + - name: Build Angular App for production + run: npm run build -- --configuration=production + + - name: Upload Build Artifact + uses: actions/upload-artifact@v4 + with: + name: angular-dist + path: dist/ + docker: + runs-on: ubuntu-latest + steps: + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ vars.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Build and push + uses: docker/build-push-action@v6 + with: + push: true + tags: ${{ vars.DOCKERHUB_USERNAME }}/angular-demo-application:latest + cache-from: type=gha + cache-to: type=gha,mode=max diff --git a/.vscode/extensions.json b/.vscode/extensions.json deleted file mode 100644 index 77b3745..0000000 --- a/.vscode/extensions.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - // For more information, visit: https://go.microsoft.com/fwlink/?linkid=827846 - "recommendations": ["angular.ng-template"] -} diff --git a/.vscode/launch.json b/.vscode/launch.json deleted file mode 100644 index 740e35a..0000000 --- a/.vscode/launch.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 - "version": "0.2.0", - "configurations": [ - { - "name": "ng serve", - "type": "pwa-chrome", - "request": "launch", - "preLaunchTask": "npm: start", - "url": "http://localhost:4200/" - }, - { - "name": "ng test", - "type": "chrome", - "request": "launch", - "preLaunchTask": "npm: test", - "url": "http://localhost:9876/debug.html" - } - ] -} diff --git a/.vscode/tasks.json b/.vscode/tasks.json deleted file mode 100644 index a298b5b..0000000 --- a/.vscode/tasks.json +++ /dev/null @@ -1,42 +0,0 @@ -{ - // For more information, visit: https://go.microsoft.com/fwlink/?LinkId=733558 - "version": "2.0.0", - "tasks": [ - { - "type": "npm", - "script": "start", - "isBackground": true, - "problemMatcher": { - "owner": "typescript", - "pattern": "$tsc", - "background": { - "activeOnStart": true, - "beginsPattern": { - "regexp": "(.*?)" - }, - "endsPattern": { - "regexp": "bundle generation complete" - } - } - } - }, - { - "type": "npm", - "script": "test", - "isBackground": true, - "problemMatcher": { - "owner": "typescript", - "pattern": "$tsc", - "background": { - "activeOnStart": true, - "beginsPattern": { - "regexp": "(.*?)" - }, - "endsPattern": { - "regexp": "bundle generation complete" - } - } - } - } - ] -} diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..0214021 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,39 @@ +# ------------------------------------------------- +# 1) Build-Stage +# ------------------------------------------------- +FROM node:22.16.0-alpine AS builder + +# Arbeitsverzeichnis im Container +WORKDIR /app + +# Nur package.json und lockfile kopieren, um Layer-Caching zu ermöglichen +COPY package*.json ./ + +# Abhängigkeiten installieren +RUN npm ci --legacy-peer-deps + +# Rest des Quellcodes kopieren +COPY . . + +# Angular CLI lokal installieren (falls nicht in devDependencies) +RUN npm install @angular/cli@latest --no-save + +# Anwendung bauen +RUN npx ng build --configuration=production + +# ------------------------------------------------- +# 2) Production-Stage +# ------------------------------------------------- +FROM nginx:1.25-alpine AS production + +# Entferne standardmäßiges nginx HTML +RUN rm -rf /usr/share/nginx/html/* + +# Kopiere die gebauten Dateien aus dem Builder +COPY --from=builder /app/dist/angular-demo-application /usr/share/nginx/html + +# Exponiere Port +EXPOSE 80 + +# Default-Command +CMD ["nginx", "-g", "daemon off;"] diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 0000000..717b7d8 --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2025 Kirill Esau + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md index 7d19527..7ffbe86 100644 --- a/README.md +++ b/README.md @@ -1,27 +1,10 @@ -# AngularDemoApplication +# Angular Demo Application -This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 15.0.4. +[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) +![GitHub last commit](https://img.shields.io/github/last-commit/kirillesau/angular-demo-application) +[![Build and Deploy Script](https://github.com/kirillesau/angular-demo-application/actions/workflows/build-application.yml/badge.svg?branch=master)](https://github.com/kirillesau/angular-demo-application/actions/workflows/build-application.yml) -## Development server +An example application with angular. +## Prerequisite -Run `ng serve` for a dev server. Navigate to `http://localhost:4200/`. The application will automatically reload if you change any of the source files. - -## Code scaffolding - -Run `ng generate component component-name` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module`. - -## Build - -Run `ng build` to build the project. The build artifacts will be stored in the `dist/` directory. - -## Running unit tests - -Run `ng test` to execute the unit tests via [Karma](https://karma-runner.github.io). - -## Running end-to-end tests - -Run `ng e2e` to execute the end-to-end tests via a platform of your choice. To use this command, you need to first add a package that implements end-to-end testing capabilities. - -## Further help - -To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI Overview and Command Reference](https://angular.io/cli) page. +The example has been created for learning purposes only.