在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):ansible/django-gulp-nginx开源软件地址(OpenSource Url):https://github.com/ansible/django-gulp-nginx开源编程语言(OpenSource Language):JavaScript 27.6%开源软件介绍(OpenSource Introduction):django-gulp-nginxA framework for building containerized django applications. Utilizes Ansible Container to manage each phase of the application lifecycle, and enables you to begin developing immediately with containers. Includes django, gulp, nginx, and postgresql services, pre-configured to work together, and ready for development. You can easily adjust the settings of each, as well as drop in new services directly from Ansible Galaxy. The following topics will help you get started:
RequirementsBefore starting, you'll need to have the following:
Getting StartedTo start creating your Django application, create a new directory, and initialize it with a copy of this project:
Next, build a local copy of the project's images. From the new project directory, start the build process by running the following: # Create the container images
$ ansible-container build The build process will take a few minutes to complete. It will take longer the first time you run it, because it needs to pull the base image, and build the Conductor image. After the Conductor build completes, each service in the container.yml file will be built. Services are built by executing one or more Ansible roles, and as the build process progresses, task names will scroll across your session window as each role executes. Once completed, you'll have a local copy of the built images that can be used to run the application. When you're ready to start the application, run the following: # Start the containers
$ ansible-container run Requests are proxied through the gulp service. Before you can view the sample web page, the gulp web server needs to be started. This may take a couple moments, as the process first install node modules and bower components prior to starting the service. You can watch the logs by running the following: # Watch the logs for gulp service
$ docker logs -f demo_gulp_1 The following message in the logs indicates the service is running:
To view the sample app, open a browser and go to http://localhost:8080, where you'll see a simple "Hello World!" message. DevelopingWhen you start the containers with The frontend code can be found in the src directory, and the backend django code is found in the project directory. You can begin making changes right away, and as you do, you'll see the results reflected in your browser almost immediately. Here's a brief overview of each of the running services: gulpWhile developing, the gulp service will actively watch for changes to files in the src directory tree, where custom frontend components (i.e. html, javascript, css, etc.) live. As new files are created, or existing files modified, the gulp service will compile the updates, place results in the dist directory, and using browsersync, refresh your browser. In addition to compiling the frontend components, the gulp service will proxy requests beginning with /static or /admin to the django service. The proxy settings are configurable in gulpfile.js, so as you add additional routes to the django service, you can expand the number of paths forwarded by the gulp service. NOTE
djangoThe django service provides the backend of the application. During development the runserver process executes, and accepts requests from the gulp service. The source code to the Django app lives in the project directory tree. To add additional Python and Django modules, add the module names and versions to requirements.txt, and run the When the django container starts, it waits for the PostgreSQL database to be ready, and then it performs migrations, all before starting the server process. Use postgresqlThe postgresql service provides the django service with access to a database, and by default stores the database on the postgres-data volume. Modify container.ym to set the database name, and credentials. Adding ServicesYou can add preconfigured services to the application by installing Container Enabled roles directly from the Galaxy web site. Look for roles on the site by going to the Browse Roles page, setting the filter to Role Type, and choosing Containr Enabled. For example, if you want to install a Redis service, you can install the
After the install completes, the new service will be included in container.yml. You'll then need to run the # Rebuild the project images
$ ansible-container build After the build process completes, restart the application by running the following: # Run the application
$ ansible-container restart TestingAfter you've made changes to the app, and you're ready to test, you'll first run Once the new images are built, run the following to test the images: # Restart the application in production mode for testing
$ ansible-container stop
$ ansible-container run --production The above starts the containers in production mode, ignoring the dev_overrides section of each service definition in container.yml`, and executing the containers as if they were deployed to production. This time the django, nginx, and postgresql containers starts, and the gulp container stops. Just as before, access the application at http://localhost:8080. djangoIn production this service will run the gunicorn process to accept requests from the nginx service. Just as before, when the service starts it will wait for the PostgreSQL database to become available, and then perform migrations, before starting the server process. nginxThis service will respond to requests for frontend assets, and proxy requests to django service endpoints. Before running postgresqlJust as before, the postgresql sevice provides the django service with access to a database, and by default stores the database on the postgres-data volume. NOTE
DeployingAnsible Container can deploy to Kubernetes and OpenShift. For the purposes of demonstrating the deployment workflow, we'll use OpenShift. If you want to carry out the actual steps, you'll need access to an OpenShift instance. The Install and Configure Openshift guide at our doc site provides a how-to that will help you create a containerized instance. Log into the cluster using your developer account: # Log into the local cluster
$ oc login -u developer Create a demo project: # Create a new project
$ oc new-project demo The project name is defined in container.yml. Within the settings section, you will find a k8s_namespace section that sets the name. The project name is arbitrary. However, before running the Next, use the One of the registry attributes is namespace. For OpenShift and K8s, the registry namespace should match the name value set in k8s_namespace within the settings section. In the case of OpenShift, the name in k8s_namespace will be the project name, and for K8s, it's the Namespace. Once you're ready to push the images, run the following from the root of the demo project directory: # Push the built images and generate the deployment playbook
$ ansible-container --engine openshift deploy --push-to local_openshift --username developer --password $(oc whoami -t) The above will authenticate to the registry using the After pushing the images, a playbook is generated and written to the You will also find a To deploy the application, execute the playbook, making sure to include the appropriate tag. Possible tags include: # Run the deployment playbook
$ ansible-playbook ./ansible-deployment/demo.yml --tags start Once the playbook completes, log into the OpenShift console to check the status of the deployment. From the Applications menu, choose Routes, and find the URL that points to the nginx service. Using this URL, you can access the appication running on the cluster. ContributingIf you work with this project and find issues, please submit an issue. Pull requests are welcome. If you want to help add features and maintain the project, please feel free to jump in, and we'll review your request quickly, and help you get it merged. DependenciesThis project depends on the following Galaxy roles: LicenseAuthorsView AUTHORS for a list contributors. Thanks everyone! |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论