Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(ci): Set correct GIT_* on all images #16705

Merged
merged 20 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 31 additions & 8 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ jobs:
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}

- name: Set up QEMU
uses: docker/setup-qemu-action@v1
uses: docker/setup-qemu-action@v3
with:
image: '${{ env.DOCKER_BASE_IMAGE_REGISTRY }}/eks-distro-build-tooling/binfmt-misc:qemu-v6.1.0'
- name: Set up Docker Buildx
Expand Down Expand Up @@ -552,7 +552,7 @@ jobs:
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}

- name: Set up QEMU
uses: docker/setup-qemu-action@v1
uses: docker/setup-qemu-action@v3
with:
image: '${{ env.DOCKER_BASE_IMAGE_REGISTRY }}/eks-distro-build-tooling/binfmt-misc:qemu-v6.1.0'
- name: Set up Docker Buildx
Expand All @@ -561,6 +561,25 @@ jobs:
driver-opts: |
image=${{vars.AWS_ECR_REPO_BASE}}/moby/buildkit:buildx-stable-1

- name: Prepare Docker build arguments
id: dockerargs
if: steps.gather.outcome == 'success'
env:
NODE_IMAGE_TAG: ${{ needs.prepare.outputs.NODE_IMAGE_TAG }}
SHA: ${{ github.sha }}
DOCKER_BASE_IMAGE_REGISTRY: ${{ env.DOCKER_BASE_IMAGE_REGISTRY }}
run: |
set -x
build_args=(
--build-arg="DOCKER_IMAGE_REGISTRY=${DOCKER_BASE_IMAGE_REGISTRY}"
--build-arg="NODE_IMAGE_TAG=${NODE_IMAGE_TAG}"
--build-arg="GIT_BRANCH=${GIT_BRANCH}"
--build-arg="GIT_SHA=${SHA}"
--build-arg="GIT_REPOSITORY_URL=${{ github.server_url }}/${{ github.repository }}"
)
export EXTRA_DOCKER_BUILD_ARGS="${build_args[*]}"
echo "EXTRA_DOCKER_BUILD_ARGS=${EXTRA_DOCKER_BUILD_ARGS}" >> "${GITHUB_ENV}"

- name: Building Docker images
continue-on-error: true
id: dockerbuild
Expand All @@ -570,9 +589,11 @@ jobs:
SHA: ${{ github.sha }}
DOCKER_BASE_IMAGE_REGISTRY: ${{ env.DOCKER_BASE_IMAGE_REGISTRY }}
run: |
echo "Node image tag is: '$NODE_IMAGE_TAG'"
export EXTRA_DOCKER_BUILD_ARGS="--build-arg DOCKER_IMAGE_REGISTRY=$DOCKER_BASE_IMAGE_REGISTRY --build-arg GIT_SHA=$SHA --build-arg NODE_IMAGE_TAG=$NODE_IMAGE_TAG"
./scripts/ci/run-in-parallel.sh "90_$DOCKER_TYPE"
set -x
echo "Node image tag is: '${NODE_IMAGE_TAG}'"
echo "Docker build args are: 'EXTRA_DOCKER_BUILD_ARGS'"
export EXTRA_DOCKER_BUILD_ARGS
./scripts/ci/run-in-parallel.sh "90_${DOCKER_TYPE}"

- name: Building Docker images Retry
if: steps.gather.outcome == 'success' && steps.dockerbuild.outcome == 'failure'
Expand All @@ -581,9 +602,11 @@ jobs:
SHA: ${{ github.sha }}
DOCKER_BASE_IMAGE_REGISTRY: ${{ env.DOCKER_BASE_IMAGE_REGISTRY }}
run: |
echo "Node image tag is: '$NODE_IMAGE_TAG'"
export EXTRA_DOCKER_BUILD_ARGS="--build-arg DOCKER_IMAGE_REGISTRY=$DOCKER_BASE_IMAGE_REGISTRY --build-arg GIT_SHA=$SHA --build-arg NODE_IMAGE_TAG=$NODE_IMAGE_TAG"
./scripts/ci/run-in-parallel.sh "90_$DOCKER_TYPE"
set -x
echo "Node image tag is: '${NODE_IMAGE_TAG}'"
echo "Docker build args are: 'EXTRA_DOCKER_BUILD_ARGS'"
export EXTRA_DOCKER_BUILD_ARGS
./scripts/ci/run-in-parallel.sh "90_${DOCKER_TYPE}"

helm-docker-build:
needs:
Expand Down
68 changes: 35 additions & 33 deletions scripts/ci/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
ARG PLAYWRIGHT_VERSION
ARG DOCKER_IMAGE_REGISTRY=public.ecr.aws
ARG NODE_IMAGE_TAG

FROM ${DOCKER_IMAGE_REGISTRY}/docker/library/node:${NODE_IMAGE_TAG} AS deps

# hadolint ignore=DL3018
Expand Down Expand Up @@ -35,14 +36,8 @@ ENV NODE_OPTIONS="--max-old-space-size=8192"

RUN yarn run build ${APP} --prod

# This is base image for containers that are to be deployed
FROM ${DOCKER_IMAGE_REGISTRY}/docker/library/node:${NODE_IMAGE_TAG} AS output-base
# this is base image for containers that are to be deployed
ARG GIT_BRANCH
ARG GIT_SHA
LABEL branch=${GIT_BRANCH}
LABEL commit=${GIT_SHA}
ENV GIT_BRANCH=${GIT_BRANCH}
ENV GIT_SHA=${GIT_SHA}
ARG APP
ARG APP_HOME
ARG APP_DIST_HOME
Expand All @@ -65,40 +60,36 @@ RUN npm install -g \
USER runner

FROM output-base-with-pg AS output-express
ARG GIT_SHA
ENV DD_GIT_COMMIT_SHA="${GIT_SHA}"
ENV DD_GIT_REPOSITORY_URL="github.com/island-is/island.is"

COPY --from=builder /build/${APP_DIST_HOME} /webapp/

ARG GIT_BRANCH GIT_SHA GIT_REPOSITORY_URL
ENV GIT_BRANCH=${GIT_BRANCH} GIT_SHA=${GIT_SHA} GIT_REPOSITORY_URL=${GIT_REPOSITORY_URL}
ENV DD_GIT_BRANCH=${GIT_BRANCH} DD_GIT_SHA=${GIT_SHA} DD_GIT_REPOSITORY_URL=${GIT_REPOSITORY_URL}
LABEL branch=${GIT_BRANCH}
LABEL commit=${GIT_SHA}
AndesKrrrrrrrrrrr marked this conversation as resolved.
Show resolved Hide resolved
ENTRYPOINT []
CMD [ "node", "--no-experimental-fetch", "main.js" ]

FROM output-base-with-pg AS output-next
ARG GIT_SHA
ENV DD_GIT_COMMIT_SHA="${GIT_SHA}"
ENV DD_GIT_REPOSITORY_URL="github.com/island-is/island.is"
ENV PORT=4200

# TODO: smallify
COPY --from=deps /build/node_modules /webapp/node_modules
COPY --from=builder /build/${APP_DIST_HOME} /webapp/

ARG GIT_BRANCH GIT_SHA GIT_REPOSITORY_URL
ENV GIT_BRANCH=${GIT_BRANCH} GIT_SHA=${GIT_SHA} GIT_REPOSITORY_URL=${GIT_REPOSITORY_URL}
ENV DD_GIT_BRANCH=${GIT_BRANCH} DD_GIT_SHA=${GIT_SHA} DD_GIT_REPOSITORY_URL=${GIT_REPOSITORY_URL}
LABEL branch=${GIT_BRANCH}
LABEL commit=${GIT_SHA}
ENTRYPOINT [ "node", "main.js" ]

FROM $DOCKER_IMAGE_REGISTRY/nginx/nginx:1.21-alpine AS output-static
FROM ${DOCKER_IMAGE_REGISTRY}/nginx/nginx:1.21-alpine AS output-static
ARG APP
ARG APP_DIST_HOME
ARG GIT_BRANCH
ARG GIT_SHA
LABEL branch=${GIT_BRANCH}
LABEL commit=${GIT_SHA}
ENV GIT_BRANCH=${GIT_BRANCH}
ENV GIT_SHA=${GIT_SHA}
ENV APP=${APP}
ENV BASEPATH=/
ENV DD_GIT_COMMIT_SHA="${GIT_SHA}"
ENV DD_GIT_REPOSITORY_URL="github.com/island-is/island.is"

RUN mkdir -p /etc/nginx/templates
# hadolint ignore=DL3018
Expand All @@ -111,6 +102,12 @@ COPY scripts/dockerfile-assets/bash/extract-environment.sh /docker-entrypoint.d
COPY scripts/dockerfile-assets/bash/extract-environment.js /docker-entrypoint.d
COPY --from=builder /build/${APP_DIST_HOME} /usr/share/nginx/html

ARG GIT_BRANCH GIT_SHA GIT_REPOSITORY_URL
ENV GIT_BRANCH=${GIT_BRANCH} GIT_SHA=${GIT_SHA} GIT_REPOSITORY_URL=${GIT_REPOSITORY_URL}
ENV DD_GIT_BRANCH=${GIT_BRANCH} DD_GIT_SHA=${GIT_SHA} DD_GIT_REPOSITORY_URL=${GIT_REPOSITORY_URL}
LABEL branch=${GIT_BRANCH}
LABEL commit=${GIT_SHA}

FROM output-base AS output-jest

RUN echo 'module.exports = {};' > jest.config.js
Expand All @@ -122,24 +119,19 @@ COPY --from=builder /build/${APP_DIST_HOME} /webapp/

USER runner

ARG GIT_BRANCH GIT_SHA GIT_REPOSITORY_URL
ENV GIT_BRANCH=${GIT_BRANCH} GIT_SHA=${GIT_SHA} GIT_REPOSITORY_URL=${GIT_REPOSITORY_URL}
ENV DD_GIT_BRANCH=${GIT_BRANCH} DD_GIT_SHA=${GIT_SHA} DD_GIT_REPOSITORY_URL=${GIT_REPOSITORY_URL}
LABEL branch=${GIT_BRANCH}
LABEL commit=${GIT_SHA}
CMD [ "jest", "main.spec.js" ]



FROM mcr.microsoft.com/playwright:v${PLAYWRIGHT_VERSION}-focal AS playwright-base






FROM playwright-base AS output-playwright
ARG GIT_BRANCH
ARG GIT_SHA
LABEL branch=${GIT_BRANCH}
LABEL commit=${GIT_SHA}
ENV GIT_BRANCH=${GIT_BRANCH}
ENV GIT_SHA=${GIT_SHA}

# TODO: remove awscli dependency (157 MB extra)

# hadolint ignore=DL3008
Expand All @@ -165,6 +157,11 @@ RUN yarn playwright install ${PLAYWRIGHT_BROWSER}

COPY --chown=pwuser:pwuser --chmod=0755 ${APP_HOME}/entrypoint.sh .

ARG GIT_BRANCH GIT_SHA GIT_REPOSITORY_URL
ENV GIT_BRANCH=${GIT_BRANCH} GIT_SHA=${GIT_SHA} GIT_REPOSITORY_URL=${GIT_REPOSITORY_URL}
ENV DD_GIT_BRANCH=${GIT_BRANCH} DD_GIT_SHA=${GIT_SHA} DD_GIT_REPOSITORY_URL=${GIT_REPOSITORY_URL}
LABEL branch=${GIT_BRANCH}
LABEL commit=${GIT_SHA}
ENTRYPOINT ["./entrypoint.sh"]


Expand All @@ -183,6 +180,11 @@ COPY --chown=pwuser:pwuser --chmod=0755 ${APP_HOME}/entrypoint.sh .

USER pwuser

ARG GIT_BRANCH GIT_SHA GIT_REPOSITORY_URL
ENV GIT_BRANCH=${GIT_BRANCH} GIT_SHA=${GIT_SHA} GIT_REPOSITORY_URL=${GIT_REPOSITORY_URL}
ENV DD_GIT_BRANCH=${GIT_BRANCH} DD_GIT_SHA=${GIT_SHA} DD_GIT_REPOSITORY_URL=${GIT_REPOSITORY_URL}
LABEL branch=${GIT_BRANCH}
LABEL commit=${GIT_SHA}
ENTRYPOINT ["./entrypoint.sh"]

FROM output-base AS output-native
Expand Down
Loading