Skip to content

Commit

Permalink
feat: Added dev and prod targets. (#395)
Browse files Browse the repository at this point in the history
* feat: Added dev and prod targets.

* fix: removed unnecessary code.

* fix: removed matrix

* fix: added two missinig steps.

* fix: removed variant and port from builx command.

* fix: updated targets in make file.

* fix: cookiie-cutter removed from step name
  • Loading branch information
zubairshakoorarbisoft authored Nov 3, 2023
1 parent 55b53a2 commit ce9b56d
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,17 @@ jobs:
- name: Checkout
uses: actions/checkout@v2

- name: Build and Push docker image
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Build and push production docker image
env:
DOCKERHUB_PASSWORD: ${% raw %}{{ secrets.DOCKERHUB_PASSWORD }}{% endraw %}
DOCKERHUB_USERNAME: ${% raw %}{{ secrets.DOCKERHUB_USERNAME }}{% endraw %}
run : make docker_tag_build_push

- name: Build and push development docker image
env:
DOCKERHUB_PASSWORD: ${% raw %}{{ secrets.DOCKERHUB_PASSWORD }}{% endraw %}
DOCKERHUB_USERNAME: ${% raw %}{{ secrets.DOCKERHUB_USERNAME }}{% endraw %}
run : make github_docker_push
run : make docker_tag_build_push_dev
23 changes: 22 additions & 1 deletion cookiecutter-django-ida/{{cookiecutter.repo_name}}/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,16 @@ RUN locale-gen en_US.UTF-8
ENV LANG en_US.UTF-8
ENV LANGUAGE en_US:en
ENV LC_ALL en_US.UTF-8
ENV DJANGO_SETTINGS_MODULE {{cookiecutter.project_name}}.settings.production

EXPOSE {{cookiecutter.port}}
RUN useradd -m --shell /bin/false app

WORKDIR /edx/app/{{cookiecutter.repo_name}}

FROM app as prod

ENV DJANGO_SETTINGS_MODULE {{cookiecutter.project_name}}.settings.production

# Copy the requirements explicitly even though we copy everything below
# this prevents the image cache from busting unless the dependencies have changed.
COPY requirements/production.txt /edx/app/{{cookiecutter.repo_name}}/requirements/production.txt
Expand All @@ -65,3 +68,21 @@ CMD gunicorn --workers=2 --name {{cookiecutter.repo_name}} -c /edx/app/{{cookiec
# This line is after the requirements so that changes to the code will not
# bust the image cache
COPY . /edx/app/{{cookiecutter.repo_name}}

FROM app as dev

ENV DJANGO_SETTINGS_MODULE {{cookiecutter.project_name}}.settings.devstack

# Copy the requirements explicitly even though we copy everything below
# this prevents the image cache from busting unless the dependencies have changed.
COPY requirements/dev.txt /edx/app/{{cookiecutter.repo_name}}/requirements/dev.txt

RUN pip install -r requirements/dev.txt

# After the requirements so changes to the code will not bust the image cache
COPY . /edx/app/{{cookiecutter.repo_name}}

# Devstack related step for backwards compatibility
RUN touch {{cookiecutter.project_name}}/{{cookiecutter.project_name}}_env

CMD while true; do python ./manage.py runserver 0.0.0.0:{{cookiecutter.port}}; sleep 2; done
16 changes: 6 additions & 10 deletions cookiecutter-django-ida/{{cookiecutter.repo_name}}/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -181,18 +181,14 @@ db-shell: # Run the app shell as root, enter the app's database
%-attach:
docker attach {{cookiecutter.project_name}}.$*

github_docker_build:
docker build . -f Dockerfile --target app -t openedx/{{cookiecutter.repo_name}}

github_docker_tag: github_docker_build
docker tag openedx/{{cookiecutter.repo_name}} openedx/{{cookiecutter.repo_name}}:${GITHUB_SHA}

github_docker_auth:
docker_auth:
echo "$$DOCKERHUB_PASSWORD" | docker login -u "$$DOCKERHUB_USERNAME" --password-stdin

github_docker_push: github_docker_tag github_docker_auth ## push to docker hub
docker push 'openedx/{{cookiecutter.repo_name}}:latest'
docker push "openedx/{{cookiecutter.repo_name}}:${GITHUB_SHA}"
docker_tag_build_push: docker_auth
docker buildx build -t openedx/{{cookiecutter.repo_name}}:latest -t openedx/{{cookiecutter.repo_name}}:${GITHUB_SHA} --platform linux/amd64,linux/arm64 --target prod --push .

docker_tag_build_push_dev: docker_auth
docker buildx build -t openedx/{{cookiecutter.repo_name}}-dev:latest -t openedx/{{cookiecutter.repo_name}}-dev:${GITHUB_SHA} --platform linux/amd64,linux/arm64 --target dev --push .

selfcheck: ## check that the Makefile is well-formed
@echo "The Makefile is well-formed."
Expand Down

0 comments on commit ce9b56d

Please sign in to comment.