Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Don't send staticfiles while Docker image is built

Artur Smęt60ed52e008e1
diff --git a/.circleci/config.yml b/.circleci/config.yml
index 1f8c3864bd..acd3031556 100644
--- a/.circleci/config.yml
+++ b/.circleci/config.yml
@@ -45,6 +45,7 @@ jobs:
command: |
if [ -n "$CIRCLE_TAG" ]; then
apk add --upgrade --no-cache curl libcurl
+ sh ./scripts/push_static.sh
curl -u $DEMO_DEPLOY_KEY: \
-d build_parameters[CIRCLE_JOB]=deploy \
https://circleci.com/api/v1.1/project/github/mirumee/saleor-demo/tree/master
@@ -53,7 +54,9 @@ jobs:
- run:
name: Deploy saleor master
command: |
- sh ./deploy_master.sh > /dev/null 2>&1
+ apk add --upgrade --no-cache zip py-pip
+ pip install awscli
+ sh ./scripts/deploy_master.sh > /dev/null 2>&1
workflows:
diff --git a/Dockerfile b/Dockerfile
index d05bc72ef3..9dae5a478c 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -9,6 +9,7 @@ RUN \
rm -rf /var/lib/apt/lists/*
ADD requirements.txt /app/
+RUN pip install --upgrade pip
RUN pip install -r /app/requirements.txt
@@ -34,11 +35,6 @@ RUN \
### Final image
FROM python:3.6-slim
-ARG AWS_ACCESS_KEY_ID
-ARG AWS_LOCATION
-ARG AWS_MEDIA_BUCKET_NAME
-ARG AWS_SECRET_ACCESS_KEY
-ARG AWS_STORAGE_BUCKET_NAME
ARG STATIC_URL
RUN \
@@ -55,20 +51,18 @@ COPY --from=build-nodejs /app/webpack-bundle.json /app/
COPY --from=build-nodejs /app/templates /app/templates
WORKDIR /app
+
+RUN SECRET_KEY=dummy \
+ STATIC_URL=${STATIC_URL} \
+ python3 manage.py collectstatic --no-input
+
RUN useradd --system saleor && \
- mkdir /app/media /app/static && \
+ mkdir -p /app/media /app/static && \
chown -R saleor:saleor /app/
USER saleor
-RUN SECRET_KEY=dummy \
- AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID} \
- AWS_LOCATION=${AWS_LOCATION} \
- AWS_MEDIA_BUCKET_NAME=${AWS_MEDIA_BUCKET_NAME} \
- AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY} \
- AWS_STORAGE_BUCKET_NAME=${AWS_STORAGE_BUCKET_NAME} \
- STATIC_URL=${STATIC_URL} \
- python3 manage.py collectstatic --no-input
+
EXPOSE 8000
ENV PORT 8000
diff --git a/deploy_master.sh b/scripts/deploy_master.sh
similarity index 100%
rename from deploy_master.sh
rename to scripts/deploy_master.sh
diff --git a/scripts/push_static.sh b/scripts/push_static.sh
new file mode 100755
index 0000000000..e90d7c42db
--- /dev/null
+++ b/scripts/push_static.sh
@@ -0,0 +1,14 @@
+#!/bin/bash
+
+# Push static to AWS S3
+
+docker run --rm \
+ -e SECRET_KEY=dummy \
+ -e AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID} \
+ -e AWS_LOCATION=${AWS_LOCATION} \
+ -e AWS_MEDIA_BUCKET_NAME=${AWS_MEDIA_BUCKET_NAME} \
+ -e AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY} \
+ -e AWS_STORAGE_BUCKET_NAME=${AWS_STORAGE_BUCKET_NAME} \
+ -e STATIC_URL=${STATIC_URL} \
+ ${IMAGE_NAME} \
+ python3 manage.py collectstatic --no-input