diff --git a/Jenkinsfile b/Jenkinsfile index c28bf0d2fa1f10b024edee98db52ddecd73f2b6b..f2dec8dd87ec65412cad3393a64933ed1e21b71d 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -85,6 +85,27 @@ pipeline { // } } + stage('Build and push client container') { + steps { + script { + catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') { + dir('alfa-client') { + IMAGE_TAG = generateImageTag() + + sh 'npm run ci-build-alfa-client-container' + + withCredentials([usernamePassword(credentialsId: 'jenkins-nexus-login', usernameVariable: 'USER', passwordVariable: 'PASSWORD')]) { + sh 'docker login docker.ozg-sh.de -u ${USER} -p ${PASSWORD}' + + sh "docker tag docker.ozg-sh.de/alfa-client:build-latest docker.ozg-sh.de/alfa-client:${IMAGE_TAG}" + sh "docker push docker.ozg-sh.de/alfa-client:${IMAGE_TAG}" + } + } + } + } + } + } + stage('Set Version') { when { not { diff --git a/alfa-client/apps/alfa/Caddyfile b/alfa-client/apps/alfa/Caddyfile new file mode 100644 index 0000000000000000000000000000000000000000..440e32b476cf040c1471b9646a946ee8a2f8757a --- /dev/null +++ b/alfa-client/apps/alfa/Caddyfile @@ -0,0 +1,6 @@ +:8080 { + file_server + root * /usr/share/caddy + + try_files {path} /index.html +} \ No newline at end of file diff --git a/alfa-client/apps/alfa/Dockerfile b/alfa-client/apps/alfa/Dockerfile index d69c70876f7ebb414614b0d47d7e5faeb2a44f6d..8ccc0f564746885f35f3286406323cb53fca81b2 100644 --- a/alfa-client/apps/alfa/Dockerfile +++ b/alfa-client/apps/alfa/Dockerfile @@ -1,24 +1,20 @@ -# Benutzt das vorher zu bauende Docker image "nx-build-base:x.y.z" -# Siehe ../Dockerfile.nx-build-base -FROM docker.ozg-sh.de/nx-build-base:2.0.0 AS builder +FROM caddy:2.6.4-alpine -ARG NODE_ENV -ARG CONFIGURATION +RUN adduser --system --ingroup root caddy -# Turn off Nx Daemon -ENV CI=true +WORKDIR /usr/share/caddy -WORKDIR /app/builder -COPY . . +COPY apps/alfa/Caddyfile /etc/caddy/Caddyfile -RUN echo "Building configuration: $CONFIGURATION..." +COPY dist/apps/alfa /usr/share/caddy -RUN npx nx build alfa --outputHashing=all --configuration ${CONFIGURATION:-development} \ - && ./node_modules/.bin/gzipper compress ./dist --verbose --exclude jpg,jpeg,png,ico,woff,woff2 +RUN chgrp -R 0 /usr/bin/caddy /etc/caddy /config/caddy /usr/share/caddy && \ + chmod -R g=u /usr/bin/caddy /etc/caddy /config/caddy /usr/share/caddy -FROM nginx:stable-alpine +USER caddy -WORKDIR /usr/share/nginx/html +EXPOSE 8080 8081 -COPY --from=builder /app/builder/dist/apps/alfa ./ -COPY --from=builder /app/builder/apps/alfa/nginx.conf /etc/nginx/nginx.conf +ENTRYPOINT ["/usr/bin/caddy"] + +CMD ["run", "--config", "/etc/caddy/Caddyfile", "--adapter", "caddyfile"] \ No newline at end of file diff --git a/alfa-client/apps/alfa/project.json b/alfa-client/apps/alfa/project.json index 539fb173beab9fa6efb50227f3efc49c7cc7bf37..932f9ed857394eebe857e588ed2cd2e7abea2ffb 100644 --- a/alfa-client/apps/alfa/project.json +++ b/alfa-client/apps/alfa/project.json @@ -122,6 +122,22 @@ "outputs": [ "{workspaceRoot}/coverage/apps/alfa" ] + }, + "container": { + "executor": "@nx-tools/nx-container:build", + "options": { + "engine": "docker", + "push": false, + "metadata": { + "images": [ + "docker.ozg-sh.de/alfa-client" + ], + "load": true, + "tags": [ + "build-latest" + ] + } + } } } } \ No newline at end of file diff --git a/alfa-client/package.json b/alfa-client/package.json index a1b8f575dd488352d03aed6d2315a5b1f9e6da42..a02724a20ba7b3e3d31967f73f9e0ec13ad8fce5 100644 --- a/alfa-client/package.json +++ b/alfa-client/package.json @@ -10,6 +10,7 @@ "start-for-screenreader": "nx run alfa:serve --host 192.168.178.20 --port 4300 --disable-host-check --verbose", "start:devbe": "nx run alfa:serve --port 4300 --disable-host-check --proxy-config proxy.dev.conf.json --verbose", "build": "nx run alfa:build", + "ci-build-alfa-client-container": "nx container alfa", "test": "nx affected --target=test --parallel 8 -- --runInBand", "test:cov": "jest --coverage", "test:lib": "nx test ${npm_config_lib}",