From fad4f0816c079e6667ab31a385255f95e0d8280a Mon Sep 17 00:00:00 2001 From: Karsten Thiems <150006841+typecastcloud@users.noreply.github.com> Date: Tue, 4 Jun 2024 12:44:04 +0200 Subject: [PATCH 1/4] feat(build): add full dockerfile containing yarn step We can create images without yarn installed and this change streamlines dockerfiles across portal repositories. Refs: #186 --- .conf/Dockerfile.full | 49 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 .conf/Dockerfile.full diff --git a/.conf/Dockerfile.full b/.conf/Dockerfile.full new file mode 100644 index 00000000..15d7cee9 --- /dev/null +++ b/.conf/Dockerfile.full @@ -0,0 +1,49 @@ +############################################################### +# Copyright (c) 2022 Contributors to the Eclipse Foundation +# +# See the NOTICE file(s) distributed with this work for additional +# information regarding copyright ownership. +# +# This program and the accompanying materials are made available under the +# terms of the Apache License, Version 2.0 which is available at +# https://www.apache.org/licenses/LICENSE-2.0. +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# +# SPDX-License-Identifier: Apache-2.0 +############################################################### + +# Step 1 +FROM node:21-alpine as build-step +ARG http_proxy=$http_proxy +ARG https_proxy=$https_proxy +ARG no_proxy=$no_proxy +RUN apk update && apk add --no-cache jq +COPY . /app +WORKDIR /app +RUN yarn +RUN yarn build + +# Step 2 +FROM nginxinc/nginx-unprivileged:alpine +COPY .conf/nginx.conf /etc/nginx/conf.d/default.conf +COPY --from=build-step /app/build /usr/share/nginx/html +# Change to root user +USER root +# Rename index.html to index.html.reference, to be used by env variables inject script +RUN mv /usr/share/nginx/html/index.html /usr/share/nginx/html/index.html.reference +# Create symlink for tmp for index.html to enable readOnlyRootFilesystem +RUN ln -s /tmp/index.html /usr/share/nginx/html/index.html +# Add env variables inject script and mark as executable +COPY ./scripts/inject-dynamic-env.sh /docker-entrypoint.d/00-inject-dynamic-env.sh +RUN chmod +x /docker-entrypoint.d/00-inject-dynamic-env.sh +# Install bash for env variables inject script +RUN apk update && apk add --no-cache bash +# Make nginx owner of /usr/share/nginx/html/ and change to nginx user +RUN chown -R 101:101 /usr/share/nginx/html/ +# Change to nginx user +USER 101 \ No newline at end of file From 0eaced05e394659d4c09e806aa7681f1064736b2 Mon Sep 17 00:00:00 2001 From: Karsten Thiems <150006841+typecastcloud@users.noreply.github.com> Date: Mon, 10 Jun 2024 17:20:56 +0200 Subject: [PATCH 2/4] Update Dockerfile.full --- .conf/Dockerfile.full | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.conf/Dockerfile.full b/.conf/Dockerfile.full index 15d7cee9..3ef4dbfe 100644 --- a/.conf/Dockerfile.full +++ b/.conf/Dockerfile.full @@ -1,5 +1,5 @@ ############################################################### -# Copyright (c) 2022 Contributors to the Eclipse Foundation +# Copyright (c) 2024 Contributors to the Eclipse Foundation # # See the NOTICE file(s) distributed with this work for additional # information regarding copyright ownership. @@ -46,4 +46,4 @@ RUN apk update && apk add --no-cache bash # Make nginx owner of /usr/share/nginx/html/ and change to nginx user RUN chown -R 101:101 /usr/share/nginx/html/ # Change to nginx user -USER 101 \ No newline at end of file +USER 101 From c4b75ab070e7cba97914bd9bd93ecb442945068d Mon Sep 17 00:00:00 2001 From: Karsten Thiems <150006841+typecastcloud@users.noreply.github.com> Date: Mon, 17 Jun 2024 10:18:38 +0200 Subject: [PATCH 3/4] Rename existing Dockerfile and update references in workflows --- .conf/{Dockerfile => Dockerfile.prebuilt} | 0 .conf/docker-notice-registration.md | 2 +- .github/workflows/build.yml | 2 +- .github/workflows/release-release_candidate.yml | 2 +- .github/workflows/release.yml | 2 +- .github/workflows/release_candidate.yml | 2 +- 6 files changed, 5 insertions(+), 5 deletions(-) rename .conf/{Dockerfile => Dockerfile.prebuilt} (100%) diff --git a/.conf/Dockerfile b/.conf/Dockerfile.prebuilt similarity index 100% rename from .conf/Dockerfile rename to .conf/Dockerfile.prebuilt diff --git a/.conf/docker-notice-registration.md b/.conf/docker-notice-registration.md index f0603a59..169fc27b 100644 --- a/.conf/docker-notice-registration.md +++ b/.conf/docker-notice-registration.md @@ -8,7 +8,7 @@ __Portal Frontend Registration__ - GitHub: https://github.com/eclipse-tractusx/portal-frontend-registration - Project home: https://projects.eclipse.org/projects/automotive.tractusx -- Dockerfile: https://github.com/eclipse-tractusx/portal-frontend-registration/blob/main/.conf/Dockerfile +- Dockerfile: https://github.com/eclipse-tractusx/portal-frontend-registration/blob/main/.conf/Dockerfile.prebuilt - Project license: [Apache License, Version 2.0](https://github.com/eclipse-tractusx/portal-frontend-registration/blob/main/LICENSE) __Used base images__ diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index bc405581..8979139f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -87,7 +87,7 @@ jobs: uses: docker/build-push-action@2cdde995de11925a030ce8070c3d77a52ffcf1c0 # v5.3.0 with: context: . - file: .conf/Dockerfile + file: .conf/Dockerfile.prebuilt platforms: linux/amd64, linux/arm64 push: ${{ github.event_name != 'pull_request' }} tags: ${{ steps.meta.outputs.tags }} diff --git a/.github/workflows/release-release_candidate.yml b/.github/workflows/release-release_candidate.yml index 712681ab..13f075e6 100644 --- a/.github/workflows/release-release_candidate.yml +++ b/.github/workflows/release-release_candidate.yml @@ -111,7 +111,7 @@ jobs: uses: docker/build-push-action@2cdde995de11925a030ce8070c3d77a52ffcf1c0 # v5.3.0 with: context: . - file: .conf/Dockerfile + file: .conf/Dockerfile.prebuilt platforms: linux/amd64, linux/arm64 push: ${{ github.event_name != 'pull_request' }} tags: ${{ steps.meta.outputs.tags }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 80d2585d..8bab83b6 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -112,7 +112,7 @@ jobs: uses: docker/build-push-action@2cdde995de11925a030ce8070c3d77a52ffcf1c0 # v5.3.0 with: context: . - file: .conf/Dockerfile + file: .conf/Dockerfile.prebuilt platforms: linux/amd64, linux/arm64 push: ${{ github.event_name != 'pull_request' }} tags: ${{ steps.meta.outputs.tags }} diff --git a/.github/workflows/release_candidate.yml b/.github/workflows/release_candidate.yml index dcd5e241..273a03dd 100644 --- a/.github/workflows/release_candidate.yml +++ b/.github/workflows/release_candidate.yml @@ -87,7 +87,7 @@ jobs: uses: docker/build-push-action@2cdde995de11925a030ce8070c3d77a52ffcf1c0 # v5.3.0 with: context: . - file: .conf/Dockerfile + file: .conf/Dockerfile.prebuilt platforms: linux/amd64, linux/arm64 push: ${{ github.event_name != 'pull_request' }} tags: ${{ steps.meta.outputs.tags }} From 3856763f089c514b1ec1a2bd73fa3bfed3373a9e Mon Sep 17 00:00:00 2001 From: Karsten Thiems <150006841+typecastcloud@users.noreply.github.com> Date: Mon, 17 Jun 2024 10:22:39 +0200 Subject: [PATCH 4/4] Add comments to dockerfile to describe purpose. --- .conf/Dockerfile.full | 4 ++++ .conf/Dockerfile.prebuilt | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/.conf/Dockerfile.full b/.conf/Dockerfile.full index 3ef4dbfe..e4c6022f 100644 --- a/.conf/Dockerfile.full +++ b/.conf/Dockerfile.full @@ -17,6 +17,10 @@ # SPDX-License-Identifier: Apache-2.0 ############################################################### +# +# Dockerfile with full build after checkout +# + # Step 1 FROM node:21-alpine as build-step ARG http_proxy=$http_proxy diff --git a/.conf/Dockerfile.prebuilt b/.conf/Dockerfile.prebuilt index 41474db2..c0540670 100644 --- a/.conf/Dockerfile.prebuilt +++ b/.conf/Dockerfile.prebuilt @@ -17,6 +17,10 @@ # SPDX-License-Identifier: Apache-2.0 ############################################################### +# +# Dockerfile with prebuilt webapp +# + FROM nginxinc/nginx-unprivileged:alpine COPY .conf/nginx.conf /etc/nginx/conf.d/default.conf COPY ./build /usr/share/nginx/html