Skip to content
Snippets Groups Projects
Commit d72240d8 authored by Thomas  MENARD's avatar Thomas MENARD
Browse files

Update Makefile, polls.yaml and Dockerfile

parent f5cdba78
No related branches found
No related tags found
No related merge requests found
.vscode
# Copyright 2015, Google, Inc.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# https://docs.docker.com/engine/reference/builder/
# FROM refer the image where we start from
# Here we will use a basic python 3 debian image
# [START docker]
FROM python:3
# The Google App Engine python runtime is Debian Jessie with Python installed
# and various os-level packages to allow installation of popular Python
# libraries. The source is on github at:
# https://github.com/GoogleCloudPlatform/python-docker
FROM gcr.io/google_appengine/python
# Use the RUN command to pass command to be run
# Here we update the image and add python3 virtualenv
RUN apt-get update && apt-get upgrade -y && apt-get install \
-y --no-install-recommends python3 virtualenv
# Create a virtualenv for the application dependencies.
# # If you want to use Python 2, use the -p python2.7 flag.
RUN virtualenv -p python3 /env
ENV PATH /env/bin:$PATH
# Install pip dependencies
ADD requirements.txt /app/requirements.txt
RUN /env/bin/pip install --upgrade pip && /env/bin/pip install -r /app/requirements.txt
# We add the current content of the git repo in the /app directory
ADD . /app
# We use the CMD command to start the gunicorn daemon
# when we start the container.
# Note the $PORT variable, we will need to define it when we start the container
CMD gunicorn -b :$PORT mysite.wsgi
# [END docker]
GCLOUD_PROJECT:=$(shell gcloud config list project --format="value(core.project)")
.PHONY: all
all: deploy
.PHONY: create-cluster
create-cluster:
gcloud container clusters create polls \
--scopes "https://www.googleapis.com/auth/userinfo.email","cloud-platform"
.PHONY: create-bucket
create-bucket:
gsutil mb gs://$(GCLOUD_PROJECT)
gsutil defacl set public-read gs://$(GCLOUD_PROJECT)
all: build push docker_token template deploy
.PHONY: build
build:
docker build -t gcr.io/$(GCLOUD_PROJECT)/polls .
docker build -t ${CI_REGISTRY}/${CI_PROJECT_NAME}/polls:${CI_COMMIT_SHORT_SHA} .
docker tag ${CI_REGISTRY}/${CI_PROJECT_NAME}/polls:${CI_COMMIT_SHORT_SHA} ${CI_REGISTRY}/${CI_PROJECT_NAME}/polls:latest
.PHONY: push
push: build
gcloud docker push -- gcr.io/$(GCLOUD_PROJECT)/polls
docker push -- ${CI_REGISTRY}/${CI_PROJECT_NAME}/polls
.PHONY: docker_token
docker_token:
kubectl delete secret registry-gitlab -n ${NAMESPACE} --ignore-not-found=true
kubectl create secret docker-registry -n ${NAMESPACE} registry-gitlab --docker-server=registry-gitlab.pasteur.fr --docker-username=${DEPLOY_USER} --docker-password=${DEPLOY_TOKEN} --docker-email=kubernetes@pasteur.fr
.PHONY: template
template:
sed -i ".tmpl" "s/\$$GCLOUD_PROJECT/$(GCLOUD_PROJECT)/g" polls.yaml
envsubst <polls.yaml >> deploy.yaml
.PHONY: deploy
deploy: push template
kubectl create -f polls.yaml
deploy: build template push
kubectl apply -n ${NAMESPACE} -f deploy.yaml
.PHONY: update
update:
kubectl patch deployment polls -p "{\"spec\":{\"template\":{\"metadata\":{\"labels\":{\"date\":\"`date +'%s'`\"}}}}}"
kubectl patch deployment -n ${NAMESPACE} polls -p "{\"spec\":{\"template\":{\"metadata\":{\"labels\":{\"date\":\"`date +'%s'`\"}}}}}"
.PHONY: delete
delete:
kubectl delete rc polls
kubectl delete service polls
kubectl delete deployment -n ${NAMESPACE} polls
kubectl delete service -n ${NAMESPACE} polls
kubectl delete ingress -n ${NAMESPACE} polls
# Getting started with Django on Google Container Engine
[![Open in Cloud Shell][shell_img]][shell_link]
[shell_img]: http://gstatic.com/cloudssh/images/open-btn.png
[shell_link]: https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/GoogleCloudPlatform/python-docs-samples&page=editor&open_in_editor=container_engine/django_tutorial/README.md
# Getting started with Django
This repository is an example of how to run a [Django](https://www.djangoproject.com/)
app on Google Container Engine. It uses the
app on Kubernetes. It uses the
[Writing your first Django app](https://docs.djangoproject.com/en/1.11/intro/tutorial01/)
Polls application (parts 1 and 2) as the example app to deploy. From here on
out, we refer to this app as the 'polls' application.
# Tutorial
See our [Django on Container Engine](https://cloud.google.com/python/django/container-engine) tutorial for instructions for setting up and deploying this sample application.
## Contributing changes
* See [CONTRIBUTING.md](https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/CONTRIBUTING.md)
## Licensing
* See [LICENSE](https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/LICENSE)
# Copyright 2015 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License
# This file configures the polls application . The frontend serves
# public web traffic.
# The bookshelf frontend replication controller ensures that at least 3
# instances of the bookshelf app are running on the cluster.
# For more info about Pods see:
# https://cloud.google.com/container-engine/docs/pods/
# For more info about Deployments:
# https://kubernetes.io/docs/user-guide/deployments/
# [START kubernetes_deployment]
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
......@@ -37,67 +12,30 @@ spec:
app: polls
spec:
containers:
- name: polls-app
# Replace with your project ID or use `make template`
image: gcr.io/<your-project-id>/polls
name: polls-app
image: ${CI_REGISTRY}/${CI_PROJECT_NAME}/polls:${CI_COMMIT_SHORT_SHA}
# This setting makes nodes pull the docker image every time before
# starting the pod. This is useful when debugging, but should be turned
# off in production.
imagePullPolicy: Always
env:
# [START cloudsql_secrets]
- name: DATABASE_USER
valueFrom:
secretKeyRef:
name: cloudsql
name: postgresql-credentials
key: username
- name: DATABASE_PASSWORD
valueFrom:
secretKeyRef:
name: cloudsql
name: postgresql-credentials
key: password
# [END cloudsql_secrets]
ports:
- containerPort: 8080
# [START proxy_container]
- image: gcr.io/cloudsql-docker/gce-proxy:1.05
name: cloudsql-proxy
command: ["/cloud_sql_proxy", "--dir=/cloudsql",
"-instances=<your-cloudsql-connection-string>=tcp:5432",
"-credential_file=/secrets/cloudsql/credentials.json"]
volumeMounts:
- name: cloudsql-oauth-credentials
mountPath: /secrets/cloudsql
readOnly: true
- name: ssl-certs
mountPath: /etc/ssl/certs
- name: cloudsql
mountPath: /cloudsql
# [END proxy_container]
# [START volumes]
volumes:
- name: cloudsql-oauth-credentials
- name: postgresql-credentials
secret:
secretName: cloudsql-oauth-credentials
- name: ssl-certs
hostPath:
path: /etc/ssl/certs
- name: cloudsql
emptyDir:
# [END volumes]
# [END kubernetes_deployment]
secretName: postgresql
---
# [START service]
# The polls service provides a load-balancing proxy over the polls app
# pods. By specifying the type as a 'LoadBalancer', Container Engine will
# create an external HTTP load balancer.
# For more information about Services see:
# https://cloud.google.com/container-engine/docs/services/
# For more information about external HTTP load balancing see:
# https://cloud.google.com/container-engine/docs/load-balancer
apiVersion: v1
kind: Service
metadata:
......@@ -105,10 +43,27 @@ metadata:
labels:
app: polls
spec:
type: LoadBalancer
type: ClusterIP
ports:
- port: 80
targetPort: 8080
selector:
app: polls
# [END service]
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
annotations:
kubernetes.io/ingress.class: traefik
labels:
app: polls
name: polls
spec:
rules:
- host: ${CI_PROJECT_NAME}.pasteur.cloud
http:
paths:
- backend:
serviceName: polls
servicePort: 80
path: /
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment