Skip to content

Commit

Permalink
Adding ability to push self hoisting staging docker compose serice (#…
Browse files Browse the repository at this point in the history
…1157)

Creates a self hoisting docker-compose image and enables command to push
that to a target sandbox for staging deployment.
  • Loading branch information
corps authored Sep 17, 2024
1 parent 31ce656 commit e7a084c
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 359 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ NO_SENTRY_INTEGRATION=... # Set this to 1 in develop mode to ignore Local Sentry
NO_REAL_MODELS=... # Set this to 1 in development to ignore real models and use stubs

RPC_SHARED_SECRET="seers-also-very-long-value-haha" # Match with SEER_RPC_SHARED_SECRET=[""] in sentry.conf.py
SBX_PROJECT=eng-dev-sbx--XXX # If using push-image and https://github.com/getsentry/terraform-sandboxes.private
1 change: 0 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ repos:
- id: check-executables-have-shebangs
- id: check-merge-conflict
- id: check-symlinks
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
- id: debug-statements
16 changes: 16 additions & 0 deletions Compose.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM docker:cli

ARG SBX_PROJECT
ENV SBX_PROJECT=${SBX_PROJECT}

RUN mkdir /app
WORKDIR /app

COPY .env /app/
COPY docker-compose.yml /app/
COPY docker-compose.staging.yml /app/
# Can't reset these values with overlay unfortunately
RUN grep -v 'context: .' /app/docker-compose.yml | grep -v 'build:' > /app/docker-compose.yml.2
RUN mv /app/docker-compose.yml.2 /app/docker-compose.yml

ENTRYPOINT ["/usr/local/bin/docker", "compose", "-f", "/app/docker-compose.yml", "-f", "docker-compose.staging.yml"]
20 changes: 11 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,17 @@ RUN update-alternatives --install /usr/bin/python python /usr/bin/python3.11 1 &
RUN ln -s /usr/bin/python /usr/local/bin/python && \
ln -s /usr/bin/python3 /usr/local/bin/python3

# Copy model files (assuming they are in the 'models' directory)
COPY models/ models/

# Copy setup files, requirements, and scripts
COPY setup.py requirements.txt celeryworker.sh celerybeat.sh gunicorn.sh ./

RUN chmod +x ./celeryworker.sh ./celerybeat.sh ./gunicorn.sh

# Install dependencies
COPY setup.py requirements.txt ./
RUN pip install --upgrade pip==24.0
RUN pip install -r requirements.txt --no-cache-dir

# Copy model files (assuming they are in the 'models' directory)
COPY models/ models/
# Copy scripts
COPY celeryworker.sh celerybeat.sh gunicorn.sh ./
RUN chmod +x ./celeryworker.sh ./celerybeat.sh ./gunicorn.sh

# Copy source code
COPY src/ src/
COPY pyproject.toml .
Expand All @@ -55,8 +54,11 @@ COPY supervisord.conf /etc/supervisord.conf
RUN pip install --default-timeout=120 -e . --no-cache-dir --no-deps

ENV FLASK_APP=src.seer.app:start_app()
# Set in cloudbuild.yaml for production images

# Supports sentry releases
ARG SEER_VERSION_SHA
ENV SEER_VERSION_SHA ${SEER_VERSION_SHA}
ARG SENTRY_ENVIRONMENT=production
ENV SENTRY_ENVIRONMENT ${SENTRY_ENVIRONMENT}

CMD ["/usr/bin/supervisord", "-c", "/etc/supervisord.conf"]
18 changes: 18 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,21 @@ gocd: ## Build GoCD pipelines
# Convert JSON to yaml
cd ./gocd/generated-pipelines && find . -type f \( -name '*.yaml' \) -print0 | xargs -n 1 -0 yq -p json -o yaml -i
.PHONY: gocd

HEAD_SHA:=$(shell git rev-parse --short HEAD)
TIME:=$(shell date +%F.%T)
SEER_STAGING_VERSION_SHA:=$(HEAD_SHA).$(TIME)
export SENTRY_ORG:=sentry
export SENTRY_PROJECT:=seer
push-staging:
# Ensure the google authentication helper is working. If this fails, https://cloud.google.com/artifact-registry/docs/docker/authentication#gcloud-helper
gcloud auth configure-docker us-west1-docker.pkg.dev > /dev/null
# Setup your SBX_PROJECT in .env from the sandbox project name
docker build . --platform linux/amd64 --build-arg SEER_VERSION_SHA=$(SEER_STAGING_VERSION_SHA) --build-arg SENTRY_ENVIRONMENT=staging -t us-west1-docker.pkg.dev/$(SBX_PROJECT)/staging/seer
docker build . --platform linux/amd64 -f Compose.Dockerfile --build-arg SBX_PROJECT=$(SBX_PROJECT) -t us-west1-docker.pkg.dev/$(SBX_PROJECT)/staging/seer.compose
docker push us-west1-docker.pkg.dev/$(SBX_PROJECT)/staging/seer
docker push us-west1-docker.pkg.dev/$(SBX_PROJECT)/staging/seer.compose
sentry-cli releases new "${SEER_STAGING_VERSION_SHA}"
sentry-cli releases deploys "${SEER_STAGING_VERSION_SHA}" new -e staging
sentry-cli releases finalize "${SEER_STAGING_VERSION_SHA}"
sentry-cli releases set-commits "${SEER_STAGING_VERSION_SHA}" --auto || true
Loading

0 comments on commit e7a084c

Please sign in to comment.