/djanga

Primary LanguagePython

Djanga

A Codefresh onboarding tutorial.

Use this humble repository to familiarize yourself with basic Codefresh functionality once you’ve got the development environment set up.

This project uses Python Django to start a simple web application on port 8000.

Setting up the basic build

  1. Fork this repository to your own github user.

  2. Login to your local Codefresh instance with your github account.

  3. Add a new project and select the forked Djanga repository with the default master branch.

  4. Select to use Djanga’s own Dockerfile then click the SKIP & CREATE button.

  5. Once the build is created click CLOSE & BUILD to start a new build of the project.

Now that the build has initialized, let’s return to the build settings for some

Unit testing

  1. In the Unit Test Script section enter:

    python -m unittest composeexample.utils
  2. Click Save and build (not Launch!) the project again.

  3. One very simple test should fail. Fix this test and commit it, and a new build should automatically start (github webhooks, baby!).

So the unit tests are running and the build has completed. It’s time to

Push to Docker Hub

Back in the settings, under Docker Registry:

  1. Select Docker Hub.

  2. Enter your credentials.

  3. Check Push image to docker registry.

  4. Click Save and build the project again.

Now your image is in the cloud and you’re a star! Let’s extend our testing. First we’ll set up a more complex scenario using

Compositions

Browse to the Compositions section and

  1. Add a new composition.

  2. Enter a name such as djanga-comp.

  3. Paste the following composition into the code editor and save (don’t forget to replace $DOCKER_HUB_USERNAME):

db: # Create a `Postgres` database in a container named `db`
  image: postgres

web: # Create a container for the Django web application named `web`

  image: '$DOCKER_HUB_USERNAME/djanga:master' # Base the container on the image we pushed in the previous stage

  # Use `netcat` to wait for the db before starting the webapp
  command: bash -c "echo \"Waiting for DB\"; while ! nc -z db 5432; do sleep 0.1; done; python manage.py runserver 0.0.0.0:8000"

  ports:
    - '8000:8000'

  links:
    - db

Now that we’ve got a composition all set up, let’s return to the build settings and add an

Integration test

Under the Integration Test Script section paste the following script, then save and Build again:

echo "Starting test"

# Create a new container, link it to the web container (created in the composition) and test the webapp with a curl request.
# In the context of an integration test, all containers create in the composition are prefixed with `integration_` and suffixed by the container's index
docker run -it --link integration_web_1:web phusion/baseimage bash -c "curl --silent \"http://web:8000\" > /dev/null"

exit=$?

And there you have it!