Skip to content

Commit

Permalink
misc: changes to website deployment flow (#388)
Browse files Browse the repository at this point in the history
  • Loading branch information
fernando-az-alpaca authored Dec 20, 2023
1 parent 411a010 commit 3bcf5f1
Show file tree
Hide file tree
Showing 4 changed files with 544 additions and 329 deletions.
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.dockerignore
Dockerfile
31 changes: 31 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Install dependencies only when needed
FROM python:3.11 AS deps

ARG POETRY_VERSION=1.6.1
ENV POETRY_VERSION ${POETRY_VERSION}

RUN pip install --no-cache-dir poetry==${POETRY_VERSION}

# Build the docs
FROM deps AS builder

WORKDIR /app

COPY . .

# for the config line below, see https://github.com/python-poetry/poetry/issues/7611#issuecomment-1747836233 (can be dropped with poetry >= 1.7.0)
RUN poetry config installer.max-workers 1
RUN poetry install

WORKDIR /app/docs

RUN poetry run make html

# Serve static files
FROM nginx:alpine

# COPY ./nginx.conf /etc/nginx/nginx.conf

COPY --from=builder /app/docs/_build/html /usr/share/nginx/html

ENTRYPOINT ["nginx", "-g", "daemon off;"]
78 changes: 78 additions & 0 deletions cloudbuild.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
steps:
- name: 'gcr.io/cloud-builders/docker'
id: 'pull image cache'
entrypoint: 'bash'
args:
- -c
- |
docker pull gcr.io/$PROJECT_ID/alpaca-py:deps || true
- name: 'gcr.io/cloud-builders/docker'
id: 'deps build'
args: [
'build',
'--target', 'deps',
'-t', 'gcr.io/$PROJECT_ID/alpaca-py:deps',
'--cache-from', 'gcr.io/$PROJECT_ID/alpaca-py:deps',
'.'
]

- name: 'gcr.io/cloud-builders/docker'
id: 'build image'
args: [
'build',
'-t', 'gcr.io/$PROJECT_ID/alpaca-py:latest',
'--cache-from', 'gcr.io/$PROJECT_ID/alpaca-py:deps',
'.'
]

- name: 'gcr.io/cloud-builders/docker'
id: 'push images'
entrypoint: 'sh'
args:
- -c
- |
set -eu
if [ "$TAG_NAME" = "" ] && [ "$BRANCH_NAME" = "master" ]; then
docker tag gcr.io/$PROJECT_ID/alpaca-py:latest gcr.io/$PROJECT_ID/alpaca-py:${BRANCH_NAME}-latest
docker push gcr.io/$PROJECT_ID/alpaca-py:${BRANCH_NAME}-latest
fi
if [ "$TAG_NAME" != "" ]; then
docker tag gcr.io/$PROJECT_ID/alpaca-py:latest gcr.io/$PROJECT_ID/alpaca-py:$TAG_NAME
docker push gcr.io/$PROJECT_ID/alpaca-py:$TAG_NAME
else
docker push gcr.io/$PROJECT_ID/alpaca-py:deps
docker push gcr.io/$PROJECT_ID/alpaca-py:latest
fi
- name: 'gcr.io/cloud-builders/kubectl'
id: 'deploy to staging or master as appropriate'
entrypoint: 'sh'
secretEnv: ['SA_TOKEN_STAGING','SA_TOKEN_MASTER']
args:
- -c
- |
set -eu
if [ "$TAG_NAME" = "" ] && [ "$BRANCH_NAME" = "master" ] ; then
SA_TOKEN="$$SA_TOKEN_STAGING"
elif [ "$TAG_NAME" != "" ]; then
SA_TOKEN="$$SA_TOKEN_MASTER"
fi
if [ "$_KUBE_API_SERVER" != "" -a "$_KUBE_CA_CRT" != "" -a "$_KUBE_NAMESPACE" != "" -a "$_KUBE_DEPLOYMENT" != "" -a "$$SA_TOKEN" != "" ]; then
echo "$_KUBE_CA_CRT" > /tmp/ca.crt
if [ "$TAG_NAME" != "" ]; then
kubectl --certificate-authority /tmp/ca.crt --server "$_KUBE_API_SERVER" --namespace "$_KUBE_NAMESPACE" --token "$$SA_TOKEN" set image deploy "$_KUBE_DEPLOYMENT" nginx=gcr.io/$PROJECT_ID/alpaca-py:$TAG_NAME
fi
kubectl --certificate-authority /tmp/ca.crt --server "$_KUBE_API_SERVER" --namespace "$_KUBE_NAMESPACE" --token "$$SA_TOKEN" rollout restart deploy "$_KUBE_DEPLOYMENT"
fi
availableSecrets:
secretManager:
- versionName: projects/$PROJECT_ID/secrets/alpaca-py-staging-cloudbuild-kubernetes-sa-token/versions/latest
env: 'SA_TOKEN_STAGING'
- versionName: projects/$PROJECT_ID/secrets/alpaca-py-prod-cloudbuild-kubernetes-sa-token/versions/latest
env: 'SA_TOKEN_MASTER'

timeout: 1200s
Loading

0 comments on commit 3bcf5f1

Please sign in to comment.