diff --git a/.github/workflows/docker-image-test.yml b/.github/workflows/docker-image-test.yml index 6ed6ebe9f32f2..a85a7a5ace8db 100644 --- a/.github/workflows/docker-image-test.yml +++ b/.github/workflows/docker-image-test.yml @@ -11,6 +11,14 @@ jobs: - name: Checkout PR branch uses: actions/checkout@v2 + - name: Lint Dockerfiles with Hadolint + run: | + # Install latest Hadolint binary from GitHub (not available via apt) + HADOLINT_LATEST_TAG=$(curl --silent "https://api.github.com/repos/hadolint/hadolint/releases/latest" | jq -r .tag_name) + sudo curl -sLo /usr/bin/hadolint "https://github.com/hadolint/hadolint/releases/download/$HADOLINT_LATEST_TAG/hadolint-Linux-x86_64" + sudo chmod +x /usr/bin/hadolint + hadolint **Dockerfile + - name: Set up QEMU uses: docker/setup-qemu-action@v1 diff --git a/dev.Dockerfile b/dev.Dockerfile index 8e4f43812d6e7..d7f008a5d017c 100644 --- a/dev.Dockerfile +++ b/dev.Dockerfile @@ -3,10 +3,13 @@ ENV PYTHONUNBUFFERED 1 RUN mkdir /code WORKDIR /code +SHELL ["/bin/bash", "-o", "pipefail", "-c"] + RUN apt-get update \ - && apt-get install -y --no-install-recommends curl git build-essential \ + && apt-get install -y --no-install-recommends curl=7.64.0-4+deb10u1 git=1:2.20.1-2+deb10u3 build-essential=12.6 \ && curl -sL https://deb.nodesource.com/setup_14.x | bash - \ - && apt-get install -y --no-install-recommends nodejs \ + && apt-get install -y --no-install-recommends nodejs=14.16.0-1nodesource1 \ + && rm -rf /var/lib/apt/lists/* \ && npm install -g yarn@1 \ && yarn config set network-timeout 300000 \ && yarn --frozen-lockfile @@ -14,13 +17,12 @@ RUN apt-get update \ COPY requirements.txt /code/ COPY requirements-dev.txt /code/ # install dependencies but ignore any we don't need for dev environment -RUN pip install $(grep -ivE "psycopg2" requirements.txt | cut -d'#' -f1) --compile\ - && pip install psycopg2-binary +RUN pip install -r requirements.txt --no-cache-dir # install dev dependencies RUN mkdir /code/requirements/ COPY requirements-dev.txt /code/requirements/ -RUN pip install -r requirements-dev.txt --compile +RUN pip install -r requirements-dev.txt --compile --no-cache-dir COPY package.json /code/ COPY yarn.lock /code/ @@ -44,6 +46,6 @@ RUN DEBUG=1 DATABASE_URL='postgres:///' REDIS_URL='redis:///' python manage.py c EXPOSE 8000 EXPOSE 8234 RUN yarn install -RUN cd plugins && yarn install +RUN yarn install --cwd plugins ENV DEBUG 1 CMD ["./bin/docker-dev"] diff --git a/preview.Dockerfile b/preview.Dockerfile deleted file mode 100644 index 546552ca884f3..0000000000000 --- a/preview.Dockerfile +++ /dev/null @@ -1,72 +0,0 @@ -FROM python:3.8-slim -ENV PYTHONUNBUFFERED 1 -RUN mkdir /code -WORKDIR /code - -RUN apt-get update && apt-get install -y --no-install-recommends git gnupg \ - && apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys B97B0AFCAA1A47F044F244A07FCC7D46ACCC4CF8 \ - && echo "deb http://apt.postgresql.org/pub/repos/apt/ precise-pgdg main" > /etc/apt/sources.list.d/pgdg.list \ - && apt-get update && apt-get install -y --no-install-recommends postgresql redis-server \ - && apt-get purge -y gnupg \ - && rm -rf /var/lib/apt/lists/* - -# START POSTGRES -# Run the next command as the ``postgres`` user created by the ``postgres-9.3`` package when it was ``apt-get installed`` -USER postgres -# Create a PostgreSQL role named ``docker`` with ``docker`` as the password and -# then create a database `docker` owned by the ``docker`` role. -RUN /etc/init.d/postgresql start &&\ - psql --command "CREATE USER posthog WITH SUPERUSER PASSWORD 'posthog';" &&\ - createdb posthog -# END POSGRES - -USER root - -RUN /etc/init.d/redis-server start - -COPY requirements.txt /code/ -# install dependencies but ignore any we don't need for dev environment -RUN pip install $(grep -ivE "tblib|psycopg2|ipdb|mypy|ipython|ipdb|pip|djangorestframework-stubs|django-stubs|ipython-genutils|mypy-extensions|Pygments|typed-ast|jedi" requirements.txt | cut -d'#' -f1) --no-cache-dir --compile\ - && pip install psycopg2-binary --no-cache-dir --compile\ - && pip uninstall ipython-genutils pip -y - -COPY package.json /code/ -COPY yarn.lock /code/ -COPY webpack.config.js /code/ -COPY postcss.config.js /code/ -COPY babel.config.js /code/ -COPY tsconfig.json /code/ -COPY .kearc /code/ -COPY frontend/ /code/frontend - -RUN mkdir /code/plugins -COPY plugins/package.json /code/plugins/ -COPY plugins/yarn.lock /code/plugins/ - -RUN apt-get update && apt-get install -y --no-install-recommends curl \ - && curl -sL https://deb.nodesource.com/setup_14.x | bash - \ - && apt-get install nodejs -y --no-install-recommends \ - && npm install -g yarn@1 \ - && yarn config set network-timeout 300000 \ - && yarn --frozen-lockfile \ - && yarn build \ - && cd plugins \ - && yarn --frozen-lockfile --ignore-optional \ - && cd .. \ - && yarn cache clean \ - && apt-get purge -y curl \ - && rm -rf node_modules \ - && rm -rf /var/lib/apt/lists/* \ - && rm -rf frontend/dist/*.map - -COPY . /code/ - -RUN SECRET_KEY='unsafe secret key for build step only' DATABASE_URL='postgres:///' REDIS_URL='redis:///' python manage.py collectstatic --noinput - -RUN /etc/init.d/postgresql start\ - && SECRET_KEY='unsafe secret key for build step only' DATABASE_URL=postgres://posthog:posthog@localhost:5432/posthog REDIS_URL='redis:///' python manage.py migrate\ - && /etc/init.d/postgresql stop - -VOLUME /var/lib/postgresql -EXPOSE 8000 -ENTRYPOINT ["./bin/docker-preview"] diff --git a/production.Dockerfile b/production.Dockerfile index ab8615928eb20..0b95171bfabde 100644 --- a/production.Dockerfile +++ b/production.Dockerfile @@ -5,24 +5,24 @@ WORKDIR /code COPY . /code/ -RUN apt-get update && apt-get install -y --no-install-recommends curl git build-essential \ - && curl -sL https://deb.nodesource.com/setup_14.x | bash - \ - && apt-get install nodejs -y --no-install-recommends \ +SHELL ["/bin/bash", "-o", "pipefail", "-c"] + +RUN apt-get update \ + && apt-get install -y --no-install-recommends curl=7.64.0-4+deb10u1 git=1:2.20.1-2+deb10u3 build-essential=12.6 \ + && curl -sL https://deb.nodesource.com/setup_14.x | bash - \ + && apt-get install -y --no-install-recommends nodejs=14.16.0-1nodesource1 \ && npm install -g yarn@1 \ && yarn config set network-timeout 300000 \ && yarn --frozen-lockfile \ && yarn build \ - && cd plugins \ - && yarn --frozen-lockfile --ignore-optional \ - && cd .. \ + && yarn --cwd plugins --frozen-lockfile --ignore-optional \ && yarn cache clean \ && apt-get purge -y curl build-essential \ - && rm -rf node_modules \ - && rm -rf /var/lib/apt/lists/* + && rm -rf /var/lib/apt/lists/* \ + && rm -rf node_modules # install dependencies but ignore any we don't need for dev environment -RUN pip install $(grep -ivE "psycopg2" requirements.txt | cut -d'#' -f1) --no-cache-dir --compile\ - && pip install psycopg2-binary --no-cache-dir --compile\ +RUN pip install -r requirements.txt --no-cache-dir --compile \ && pip uninstall ipython-genutils pip -y RUN SECRET_KEY='unsafe secret key for collectstatic only' DATABASE_URL='postgres:///' REDIS_URL='redis:///' python manage.py collectstatic --noinput