diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..e9c1456 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,8 @@ +.github +.git +.editorconfig +.gitignore +.vscode +.github +dist +node_modules \ No newline at end of file diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml new file mode 100644 index 0000000..893b0fe --- /dev/null +++ b/.github/workflows/docker-publish.yml @@ -0,0 +1,106 @@ +name: Docker + +# This workflow uses actions that are not certified by GitHub. +# They are provided by a third-party and are governed by +# separate terms of service, privacy policy, and support +# documentation. + +on: + schedule: + - cron: '41 11 * * *' + push: + branches: [ "main" ] + # Publish semver tags as releases. + tags: [ 'v*.*.*' ] + pull_request: + branches: [ "main" ] + +env: + # Use docker.io for Docker Hub if empty + REGISTRY: ghcr.io + # github.repository as / + IMAGE_NAME: ${{ github.repository }} + + +jobs: + build: + + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + # This is used to complete the identity challenge + # with sigstore/fulcio when running outside of PRs. + id-token: write + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + # Install the cosign tool except on PR + # https://github.com/sigstore/cosign-installer + - name: Install cosign + if: github.event_name != 'pull_request' + uses: sigstore/cosign-installer@v3.7.0 + with: + cosign-release: 'v2.2.4' + + # Set up BuildKit Docker container builder to be able to build + # multi-platform images and export cache + # https://github.com/docker/setup-buildx-action + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3.7.1 + + # Login against a Docker registry except on PR + # https://github.com/docker/login-action + - name: Log into registry ${{ env.REGISTRY }} + if: github.event_name != 'pull_request' + uses: docker/login-action@v3.3.0 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + # Extract metadata (tags, labels) for Docker + # https://github.com/docker/metadata-action + - name: Extract Docker metadata + id: meta + uses: docker/metadata-action@v5.5.1 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + + # Build and push Docker image with Buildx (don't push on PR) + # https://github.com/docker/build-push-action + - name: Build and push Docker image + id: build-and-push + uses: docker/build-push-action@v6.9.0 + with: + context: . + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max + + # Sign the resulting Docker image digest except on PRs. + # This will only write to the public Rekor transparency log when the Docker + # repository is public to avoid leaking data. If you would like to publish + # transparency data even for private images, pass --force to cosign below. + # https://github.com/sigstore/cosign + - name: Sign the published Docker image + if: ${{ github.event_name != 'pull_request' }} + env: + # https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions#using-an-intermediate-environment-variable + TAGS: ${{ steps.meta.outputs.tags }} + DIGEST: ${{ steps.build-and-push.outputs.digest }} + # This step uses the identity token to provision an ephemeral certificate + # against the sigstore community Fulcio instance. + run: echo "${TAGS}" | xargs -I {} cosign sign --yes {}@${DIGEST} + + - name: Generate artifact attestation + if: ${{ github.event_name != 'pull_request' }} + uses: actions/attest-build-provenance@v1 + with: + subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}} + subject-digest: ${{ steps.build-and-push.outputs.digest }} + push-to-registry: true \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..54e4321 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,33 @@ +# Stage 1: Build Angular 18 App +FROM node:20 AS builder + +# Install Angular CLI globally +RUN npm install --loglevel verbose -g @angular/cli@18 + +WORKDIR /app + +# Copy package files to install dependencies +COPY package*.json ./ + +# Install dependencies +RUN npm install + +# Copy the rest of the application files +COPY . . + +# Build the Angular app for production +RUN ng build --configuration=production + + + +# Stage 2: Combine Angular and Node.js with NGINX +FROM nginx:alpine + +# Copy the Angular build from the builder stage to NGINX +COPY --from=builder /app/dist/gn-ogcapi-angular /usr/share/nginx/html +COPY docker/nginx/default.conf /etc/nginx/conf.d/default.conf +COPY docker/nginx/00-update-gn-url.sh /docker-entrypoint.d/ + + +# Expose the necessary ports +EXPOSE 80 diff --git a/README.md b/README.md index b6fe9d0..6fd0eb7 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # GnOgcapiAngular -This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 18.2.5. +This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 18.2.5 and updated to 18.2.11. ## Development server diff --git a/docker/nginx/00-update-gn-url.sh b/docker/nginx/00-update-gn-url.sh new file mode 100755 index 0000000..15b6e18 --- /dev/null +++ b/docker/nginx/00-update-gn-url.sh @@ -0,0 +1,16 @@ +#!/bin/sh + +# This script updates the GeoNetwork backend URL with the value passed in the GEONETWORK_URL environement variable + +# Check if GEONETWORK_URL is defined and not empty +if [ -n "$GEONETWORK_URL" ]; then + # Replace "http://localhost:9999" with the value of GEONETWORK_URL in main-*.js files + for file in /usr/share/nginx/html/browser/main-*.js; do + if [ -f "$file" ]; then + sed "s|http://localhost:9999|$GEONETWORK_URL|g" "$file" > "$file.tmp" && mv "$file.tmp" "$file" + echo "Updated $file with GEONETWORK_URL: $GEONETWORK_URL." + fi + done +else + echo "GEONETWORK_URL is not set or is empty. Exiting without changes." +fi \ No newline at end of file diff --git a/docker/nginx/default.conf b/docker/nginx/default.conf new file mode 100644 index 0000000..4e64cd2 --- /dev/null +++ b/docker/nginx/default.conf @@ -0,0 +1,25 @@ +server { + listen 80; + listen [::]:80; + server_name localhost; + + + #access_log /var/log/nginx/host.access.log main; + + root /usr/share/nginx/html; + index index.html; + + location / { + root /usr/share/nginx/html/browser; + try_files $uri $uri/ /index.html; + } + + #error_page 404 /404.html; + + # redirect server error pages to the static page /50x.html + # + error_page 500 502 503 504 /50x.html; + location = /50x.html { + root /usr/share/nginx/html; + } +} \ No newline at end of file