From d4972e645e47f138f67031867e16d8085fc894e8 Mon Sep 17 00:00:00 2001 From: Daan Asscheman Date: Fri, 21 Jun 2024 16:23:47 +0200 Subject: [PATCH] Use nginx on openshift. --- .github/workflows/docker-image-Laravel.yml | 44 ++++++++++++++++++++++ .github/workflows/docker-image-Nginx.yml | 44 ++++++++++++++++++++++ .github/workflows/docker-image.yml | 18 --------- openshift/nginx.dockerfile | 8 ++++ openshift/openshift-entrypoint.sh | 2 +- openshift/sample/7_nginx.yaml | 19 ++++++++++ openshift/vhost.conf | 20 ++++++++++ 7 files changed, 136 insertions(+), 19 deletions(-) create mode 100644 .github/workflows/docker-image-Laravel.yml create mode 100644 .github/workflows/docker-image-Nginx.yml delete mode 100644 .github/workflows/docker-image.yml create mode 100644 openshift/nginx.dockerfile create mode 100644 openshift/sample/7_nginx.yaml create mode 100644 openshift/vhost.conf diff --git a/.github/workflows/docker-image-Laravel.yml b/.github/workflows/docker-image-Laravel.yml new file mode 100644 index 0000000..a39bd62 --- /dev/null +++ b/.github/workflows/docker-image-Laravel.yml @@ -0,0 +1,44 @@ +name: Docker Image Laravel +env: + # 🖊️ EDIT to change the image registry settings. + # Registries such as GHCR, Quay.io, and Docker Hub are supported. + IMAGE_REGISTRY: ghcr.io/utrechtuniversity + IMAGE_REGISTRY_USER: ${{ github.actor }} + IMAGE_REGISTRY_PASSWORD: ${{ github.token }} + + +on: + push: + branches: [ "master" "develop" ] + pull_request: + branches: [ "master" ] + +jobs: + + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + - name: Build the Docker image + id: build-image + uses: redhat-actions/buildah-build@v2 + with: + image: Laravel + tags: ${{ env.IMAGE_TAGS }} + + # If you don't have a Dockerfile/Containerfile, refer to https://github.com/redhat-actions/buildah-build#scratch-build-inputs + # Or, perform a source-to-image build using https://github.com/redhat-actions/s2i-build + # Otherwise, point this to your Dockerfile/Containerfile relative to the repository root. + dockerfiles: | + ./openshift/openshift.dockerfile + - name: Push to registry + id: push-image + uses: redhat-actions/push-to-registry@v2 + with: + image: ${{ steps.build-image.outputs.image }} + tags: ${{ steps.build-image.outputs.tags }} + registry: ${{ env.IMAGE_REGISTRY }} + username: ${{ env.IMAGE_REGISTRY_USER }} + password: ${{ env.IMAGE_REGISTRY_PASSWORD }} \ No newline at end of file diff --git a/.github/workflows/docker-image-Nginx.yml b/.github/workflows/docker-image-Nginx.yml new file mode 100644 index 0000000..98b6b36 --- /dev/null +++ b/.github/workflows/docker-image-Nginx.yml @@ -0,0 +1,44 @@ +name: Docker Image Laravel +env: + # 🖊️ EDIT to change the image registry settings. + # Registries such as GHCR, Quay.io, and Docker Hub are supported. + IMAGE_REGISTRY: ghcr.io/utrechtuniversity + IMAGE_REGISTRY_USER: ${{ github.actor }} + IMAGE_REGISTRY_PASSWORD: ${{ github.token }} + + +on: + push: + branches: [ "master" "develop" ] + pull_request: + branches: [ "master" ] + +jobs: + + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + - name: Build the Docker image + id: build-image + uses: redhat-actions/buildah-build@v2 + with: + image: Nginx + tags: ${{ env.IMAGE_TAGS }} + + # If you don't have a Dockerfile/Containerfile, refer to https://github.com/redhat-actions/buildah-build#scratch-build-inputs + # Or, perform a source-to-image build using https://github.com/redhat-actions/s2i-build + # Otherwise, point this to your Dockerfile/Containerfile relative to the repository root. + dockerfiles: | + ./openshift/nginx.dockerfile + - name: Push to registry + id: push-image + uses: redhat-actions/push-to-registry@v2 + with: + image: ${{ steps.build-image.outputs.image }} + tags: ${{ steps.build-image.outputs.tags }} + registry: ${{ env.IMAGE_REGISTRY }} + username: ${{ env.IMAGE_REGISTRY_USER }} + password: ${{ env.IMAGE_REGISTRY_PASSWORD }} \ No newline at end of file diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml deleted file mode 100644 index ba997dc..0000000 --- a/.github/workflows/docker-image.yml +++ /dev/null @@ -1,18 +0,0 @@ -name: Docker Image CI - -on: - push: - branches: [ "master" ] - pull_request: - branches: [ "master" ] - -jobs: - - build: - - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v4 - - name: Build the Docker image - run: docker build . --file docker/backend.dockerfile --tag my-image-name:$(date +%s) diff --git a/openshift/nginx.dockerfile b/openshift/nginx.dockerfile new file mode 100644 index 0000000..28f7d16 --- /dev/null +++ b/openshift/nginx.dockerfile @@ -0,0 +1,8 @@ +FROM nginxinc/nginx-unprivileged:stable-alpine + +ADD ./openshift/vhost.conf /etc/nginx/conf.d/default.conf + + +# Expose port 8443 and start php-fpm server +EXPOSE 8080 +CMD ["nginx", "-g", "daemon off;"] \ No newline at end of file diff --git a/openshift/openshift-entrypoint.sh b/openshift/openshift-entrypoint.sh index d9365e0..03db54e 100644 --- a/openshift/openshift-entrypoint.sh +++ b/openshift/openshift-entrypoint.sh @@ -9,5 +9,5 @@ composer install --no-dev --no-scripts npm run build -php artisan serve --host=0.0.0.0 --port=8080 +#php artisan serve --host=0.0.0.0 --port=8080 php-fpm diff --git a/openshift/sample/7_nginx.yaml b/openshift/sample/7_nginx.yaml new file mode 100644 index 0000000..8e109d5 --- /dev/null +++ b/openshift/sample/7_nginx.yaml @@ -0,0 +1,19 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: nginx +spec: + replicas: 1 + selector: + matchLabels: + app: nginx + template: + metadata: + labels: + app: nginx + spec: + containers: + - name: nginx + image: ghcr.io/utrechtuniversity/openshift-nginx:latest + ports: + - containerPort: 8080 \ No newline at end of file diff --git a/openshift/vhost.conf b/openshift/vhost.conf new file mode 100644 index 0000000..8f612a5 --- /dev/null +++ b/openshift/vhost.conf @@ -0,0 +1,20 @@ +server { + listen 80; + server_name app.openshift.fss.uu.nl; + index index.php index.html; + root /var/www/public; + access_log /var/log/nginx/access.log; + error_log /var/log/nginx/error.log; + location / { + try_files $uri /index.php?$args; + } + + location ~ \.php$ { + fastcgi_split_path_info ^(.+\.php)(/.+)$; + fastcgi_pass backend:9000; + fastcgi_index index.php; + include fastcgi_params; + fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; + fastcgi_param PATH_INFO $fastcgi_path_info; + } +} \ No newline at end of file