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: add commit hash file to the built docker image #17833

Merged
merged 1 commit into from
Oct 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions .github/actions/build-n-cache-image/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ runs:
load: ${{ inputs.load }}
tags: ${{ steps.emit.outputs.tag }}
platforms: linux/amd64,linux/arm64
build-args: COMMIT_HASH=${{ github.sha }}
env:
ACTIONS_ID_TOKEN_REQUEST_URL: ${{ inputs.actions-id-token-request-url }}

Expand All @@ -45,5 +46,6 @@ runs:
file: production-unit.Dockerfile
tags: ${{ steps.emit.outputs.tag }}
platforms: linux/amd64
build-args: COMMIT_HASH=${{ github.sha }}
env:
ACTIONS_ID_TOKEN_REQUEST_URL: ${{ inputs.actions-id-token-request-url }}
2 changes: 2 additions & 0 deletions .github/workflows/container-images-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ jobs:
push: true
tags: posthog/posthog:${{ github.sha }},posthog/posthog:latest,${{ steps.aws-ecr.outputs.registry }}/posthog-cloud:master
platforms: linux/arm64,linux/amd64
build-args: COMMIT_HASH=${{ github.sha }}

- name: Build and push unit container image
id: build-unit
Expand All @@ -80,6 +81,7 @@ jobs:
file: production-unit.Dockerfile
tags: ${{ steps.aws-ecr.outputs.registry }}/posthog-cloud:unit
platforms: linux/amd64
build-args: COMMIT_HASH=${{ github.sha }}

- name: get deployer token
id: deployer
Expand Down
4 changes: 4 additions & 0 deletions production-unit.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
# Compile and install Node.js dependencies.
COPY ./plugin-server/package.json ./plugin-server/pnpm-lock.yaml ./plugin-server/tsconfig.json ./
COPY ./plugin-server/patches/ ./patches/
RUN apt-get update && \

Check warning on line 50 in production-unit.Dockerfile

View workflow job for this annotation

GitHub Actions / Lint changed Dockerfiles

Pin versions in apt get install. Instead of `apt-get install <package>` use `apt-get install <package>=<version>`
apt-get install -y --no-install-recommends \
"make" \
"g++" \
Expand Down Expand Up @@ -89,7 +89,7 @@
# We install those dependencies on a custom folder that we will
# then copy to the last image.
COPY requirements.txt ./
RUN apt-get update && \

Check warning on line 92 in production-unit.Dockerfile

View workflow job for this annotation

GitHub Actions / Lint changed Dockerfiles

Pin versions in apt get install. Instead of `apt-get install <package>` use `apt-get install <package>=<version>`
apt-get install -y --no-install-recommends \
"build-essential" \
"git" \
Expand Down Expand Up @@ -121,7 +121,7 @@
SHELL ["/bin/bash", "-o", "pipefail", "-c"]

# Fetch the GeoLite2-City database that will be used for IP geolocation within Django.
RUN apt-get update && \

Check warning on line 124 in production-unit.Dockerfile

View workflow job for this annotation

GitHub Actions / Lint changed Dockerfiles

Pin versions in apt get install. Instead of `apt-get install <package>` use `apt-get install <package>=<version>`
apt-get install -y --no-install-recommends \
"ca-certificates" \
"curl" \
Expand All @@ -143,7 +143,7 @@

# Install OS runtime dependencies.
# Note: please add in this stage runtime dependences only!
RUN apt-get update && \

Check warning on line 146 in production-unit.Dockerfile

View workflow job for this annotation

GitHub Actions / Lint changed Dockerfiles

Pin versions in apt get install. Instead of `apt-get install <package>` use `apt-get install <package>=<version>`

Check notice on line 146 in production-unit.Dockerfile

View workflow job for this annotation

GitHub Actions / Lint changed Dockerfiles

Delete the apt-get lists after installing something
apt-get install -y --no-install-recommends \
"chromium" \
"chromium-driver" \
Expand All @@ -153,7 +153,7 @@
"libxml2"

# Install NodeJS 18.
RUN apt-get install -y --no-install-recommends \

Check warning on line 156 in production-unit.Dockerfile

View workflow job for this annotation

GitHub Actions / Lint changed Dockerfiles

Pin versions in apt get install. Instead of `apt-get install <package>` use `apt-get install <package>=<version>`
"curl" \
&& \
curl -fsSL https://deb.nodesource.com/setup_18.x | bash - && \
Expand All @@ -168,6 +168,10 @@
chown posthog:posthog /code
USER posthog

# Add the commit hash
ARG COMMIT_HASH
RUN echo $COMMIT_HASH > /code/commit.txt

# Add in the compiled plugin-server & its runtime dependencies from the plugin-server-build stage.
COPY --from=plugin-server-build --chown=posthog:posthog /code/plugin-server/dist /code/plugin-server/dist
COPY --from=plugin-server-build --chown=posthog:posthog /code/plugin-server/node_modules /code/plugin-server/node_modules
Expand Down Expand Up @@ -206,5 +210,5 @@
# Expose the port from which we serve OpenMetrics data.
EXPOSE 8001
COPY unit.json /docker-entrypoint.d/unit.json
USER root

Check warning on line 213 in production-unit.Dockerfile

View workflow job for this annotation

GitHub Actions / Lint changed Dockerfiles

Last USER should not be root
CMD ["./bin/docker"]
6 changes: 5 additions & 1 deletion production.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#
# This Dockerfile is used for self-hosted production builds.
#
# PostHog has sunset support for self-hosted K8s deployments.
# PostHog has sunset support for self-hosted K8s deployments.
# See: https://posthog.com/blog/sunsetting-helm-support-posthog
#
# Note: for PostHog Cloud remember to update ‘Dockerfile.cloud’ as appropriate.
Expand Down Expand Up @@ -47,7 +47,7 @@
# Compile and install Node.js dependencies.
COPY ./plugin-server/package.json ./plugin-server/pnpm-lock.yaml ./plugin-server/tsconfig.json ./
COPY ./plugin-server/patches/ ./patches/
RUN apt-get update && \

Check warning on line 50 in production.Dockerfile

View workflow job for this annotation

GitHub Actions / Lint changed Dockerfiles

Pin versions in apt get install. Instead of `apt-get install <package>` use `apt-get install <package>=<version>`
apt-get install -y --no-install-recommends \
"make" \
"g++" \
Expand Down Expand Up @@ -89,7 +89,7 @@
# We install those dependencies on a custom folder that we will
# then copy to the last image.
COPY requirements.txt ./
RUN apt-get update && \

Check warning on line 92 in production.Dockerfile

View workflow job for this annotation

GitHub Actions / Lint changed Dockerfiles

Pin versions in apt get install. Instead of `apt-get install <package>` use `apt-get install <package>=<version>`
apt-get install -y --no-install-recommends \
"build-essential" \
"git" \
Expand Down Expand Up @@ -121,7 +121,7 @@
SHELL ["/bin/bash", "-o", "pipefail", "-c"]

# Fetch the GeoLite2-City database that will be used for IP geolocation within Django.
RUN apt-get update && \

Check warning on line 124 in production.Dockerfile

View workflow job for this annotation

GitHub Actions / Lint changed Dockerfiles

Pin versions in apt get install. Instead of `apt-get install <package>` use `apt-get install <package>=<version>`
apt-get install -y --no-install-recommends \
"ca-certificates" \
"curl" \
Expand All @@ -143,7 +143,7 @@

# Install OS runtime dependencies.
# Note: please add in this stage runtime dependences only!
RUN apt-get update && \

Check notice on line 146 in production.Dockerfile

View workflow job for this annotation

GitHub Actions / Lint changed Dockerfiles

Delete the apt-get lists after installing something

Check warning on line 146 in production.Dockerfile

View workflow job for this annotation

GitHub Actions / Lint changed Dockerfiles

Pin versions in apt get install. Instead of `apt-get install <package>` use `apt-get install <package>=<version>`
apt-get install -y --no-install-recommends \
"chromium" \
"chromium-driver" \
Expand All @@ -168,6 +168,10 @@
chown posthog:posthog /code
USER posthog

# Add the commit hash
ARG COMMIT_HASH
RUN echo $COMMIT_HASH > /code/commit.txt

# Add in the compiled plugin-server & its runtime dependencies from the plugin-server-build stage.
COPY --from=plugin-server-build --chown=posthog:posthog /code/plugin-server/dist /code/plugin-server/dist
COPY --from=plugin-server-build --chown=posthog:posthog /code/plugin-server/node_modules /code/plugin-server/node_modules
Expand Down
Loading