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

core: Dockerfile: Enforce style for git version #2441

Merged
merged 2 commits into from Apr 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 13 additions & 6 deletions core/Dockerfile
Expand Up @@ -2,6 +2,7 @@
FROM --platform=$BUILDPLATFORM oven/bun:1.0.3-slim AS frontendBuilder

ARG VITE_APP_GIT_DESCRIBE
ENV VITE_APP_GIT_DESCRIBE=${VITE_APP_GIT_DESCRIBE:-none/none-0-g00000000}
RUN [ -z "$VITE_APP_GIT_DESCRIBE" ] \
&& echo "VITE_APP_GIT_DESCRIBE argument not provided." \
&& echo "Use: --build-arg VITE_APP_GIT_DESCRIBE=\$(git describe --long --always --dirty --all)" \
Expand All @@ -24,6 +25,18 @@ FROM bluerobotics/blueos-base:v0.1.0
ARG TARGETARCH
ARG TARGETVARIANT

# Ensure that the git describe exists and also is in valid format as well
# The format can be invalid if someone is build BlueOS without a tag as reference
ARG GIT_DESCRIBE_TAGS
ENV GIT_DESCRIBE_TAGS=${GIT_DESCRIBE_TAGS:-0.0.0-0-g00000000}
RUN [ -z "$GIT_DESCRIBE_TAGS" ] \
&& echo "GIT_DESCRIBE_TAGS argument not provided." \
&& echo "Use: --build-arg GIT_DESCRIBE_TAGS=\$(git describe --tags --long --always)" \
&& exit 1 \
|| /bin/bash -c "[[ ! $GIT_DESCRIBE_TAGS =~ -[0-9]+-g[a-f0-9]{8}$ ]]" \
&& echo "Invalid format: $GIT_DESCRIBE_TAGS (E.g: <TAG>-<COMMIT_NUMBER>-g<SHORT_HASH>)" \
&& exit 1 || exit 0

# Set these arguments as environment variables
ENV TARGETARCH=${TARGETARCH}
ENV TARGETVARIANT=${TARGETVARIANT}
Expand Down Expand Up @@ -66,12 +79,6 @@ COPY --from=frontendBuilder /home/pi/frontend/dist /home/pi/frontend
## If the folder tree contains any files during the build step, it means we put it here by mistake.
RUN [ -z "$(find '/root/.config' -mindepth 1 -type f)" ]

ARG GIT_DESCRIBE_TAGS
RUN [ -z "$GIT_DESCRIBE_TAGS" ] \
&& echo "GIT_DESCRIBE_TAGS argument not provided." \
&& echo "Use: --build-arg GIT_DESCRIBE_TAGS=\$(git describe --tags --long --always)" \
&& exit 1 || exit 0

# Update blueosrc with the necessary environment variables
RUN RCFILE_PATH="/etc/blueosrc" \
&& echo "export GIT_DESCRIBE_TAGS=$GIT_DESCRIBE_TAGS" >> $RCFILE_PATH \
Expand Down