diff --git a/.github/workflows/ghcr.yml b/.github/workflows/ghcr.yml new file mode 100644 index 00000000..c7659113 --- /dev/null +++ b/.github/workflows/ghcr.yml @@ -0,0 +1,58 @@ +name: GHCR + +on: + workflow_dispatch: + push: + branches: [master] + tags: ["v*.*.*"] + +env: + REGISTRY: ghcr.io + +jobs: + build-push-image: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + + strategy: + matrix: + image: [nginx, service] + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 + fetch-tags: true + submodules: recursive + + - name: Log into registry ${{ env.REGISTRY }} + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract Docker metadata + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY }}/${{ github.repository_owner }}/central-${{ matrix.image }} + + - name: Set up QEMU emulator for multi-arch images + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Build and push ${{ matrix.image }} Docker image + uses: docker/build-push-action@v5 + with: + file: ${{ matrix.image }}.dockerfile + context: . + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + platforms: 'linux/amd64,linux/arm64' diff --git a/docker-compose.yml b/docker-compose.yml index 7ee34452..00ade3ba 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -77,8 +77,6 @@ services: nginx: build: context: . - args: - - OIDC_ENABLED=${OIDC_ENABLED:-false} dockerfile: nginx.dockerfile depends_on: - service @@ -90,6 +88,11 @@ services: - SENTRY_ORG_SUBDOMAIN=${SENTRY_ORG_SUBDOMAIN:-o130137} - SENTRY_KEY=${SENTRY_KEY:-3cf75f54983e473da6bd07daddf0d2ee} - SENTRY_PROJECT=${SENTRY_PROJECT:-1298632} + - OIDC_ENABLED=${OIDC_ENABLED:-false} + volumes: + - ./files/local/customssl/:/etc/customssl/live/local/:ro + - ./files/nginx/odk.conf.template:/usr/share/odk/nginx/odk.conf.template:ro + - ./files/nginx/client-config.json.template:/usr/share/odk/nginx/client-config.json.template:ro ports: - "${HTTP_PORT:-80}:80" - "${HTTPS_PORT:-443}:443" diff --git a/files/nginx/setup-odk.sh b/files/nginx/setup-odk.sh index 8e813a1d..85520dd5 100644 --- a/files/nginx/setup-odk.sh +++ b/files/nginx/setup-odk.sh @@ -1,5 +1,15 @@ #!/bin/bash + +echo "writing client config..." +if [[ $OIDC_ENABLED != 'true' ]] && [[ $OIDC_ENABLED != 'false' ]]; then + echo 'OIDC_ENABLED must be either true or false' + exit 1 +fi + +envsubst < /usr/share/odk/nginx/client-config.json.template > /usr/share/nginx/html/client-config.json + + DH_PATH=/etc/dh/nginx.pem if [ "$SSL_TYPE" != "upstream" ] && [ ! -s "$DH_PATH" ]; then openssl dhparam -out "$DH_PATH" 2048 @@ -17,7 +27,9 @@ fi # start from fresh templates in case ssl type has changed echo "writing fresh nginx templates..." +# redirector.conf gets deleted if using upstream SSL so copy it back cp /usr/share/odk/nginx/redirector.conf /etc/nginx/conf.d/redirector.conf + CNAME=$( [ "$SSL_TYPE" = "customssl" ] && echo "local" || echo "$DOMAIN") \ envsubst '$SSL_TYPE $CNAME $SENTRY_ORG_SUBDOMAIN $SENTRY_KEY $SENTRY_PROJECT' \ < /usr/share/odk/nginx/odk.conf.template \ diff --git a/nginx.dockerfile b/nginx.dockerfile index 3883b59d..7cd95395 100644 --- a/nginx.dockerfile +++ b/nginx.dockerfile @@ -9,8 +9,6 @@ RUN apt-get update \ COPY ./ ./ RUN files/prebuild/write-version.sh RUN files/prebuild/build-frontend.sh -ARG OIDC_ENABLED -RUN files/prebuild/write-client-config.sh @@ -21,17 +19,20 @@ FROM jonasal/nginx-certbot:5.0.1 EXPOSE 80 EXPOSE 443 -VOLUME [ "/etc/dh", "/etc/selfsign", "/etc/nginx/conf.d" ] -ENTRYPOINT [ "/bin/bash", "/scripts/setup-odk.sh" ] +# Persist Diffie-Hellman parameters and/or selfsign key +VOLUME [ "/etc/dh", "/etc/selfsign" ] RUN apt-get update && apt-get install -y netcat-openbsd RUN mkdir -p /usr/share/odk/nginx/ COPY files/nginx/setup-odk.sh /scripts/ -COPY files/local/customssl/*.pem /etc/customssl/live/local/ -COPY files/nginx/*.conf* /usr/share/odk/nginx/ +RUN chmod +x /scripts/setup-odk.sh + +COPY files/nginx/redirector.conf /usr/share/odk/nginx/ +COPY files/nginx/common-headers.conf /usr/share/odk/nginx/ COPY --from=intermediate client/dist/ /usr/share/nginx/html COPY --from=intermediate /tmp/version.txt /usr/share/nginx/html -COPY --from=intermediate /tmp/client-config.json /usr/share/nginx/html + +ENTRYPOINT [ "/scripts/setup-odk.sh" ]