-
Notifications
You must be signed in to change notification settings - Fork 176
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
misc: changes to website deployment flow (#388)
- Loading branch information
1 parent
411a010
commit 3bcf5f1
Showing
4 changed files
with
544 additions
and
329 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.dockerignore | ||
Dockerfile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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;"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.