Skip to content

Commit

Permalink
Merge pull request #342 from uw-it-aca/task/nginx-container
Browse files Browse the repository at this point in the history
use nginx to handle redirects
  • Loading branch information
jlaney authored Jan 22, 2025
2 parents 2ec82b4 + 6250f4a commit ddb117a
Show file tree
Hide file tree
Showing 24 changed files with 86 additions and 318 deletions.
100 changes: 8 additions & 92 deletions .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
@@ -1,48 +1,14 @@
#
# Example GitHub Actions config that drives UW-IT AXD2 integration and deployment
#
# Preconditions:
#
# 1) Application docker build is based on django-container
#
# 2) Application test suite is kicked off in docker/test.sh
#
# 3) Application repo has access to the two secrets
# at https://github.com/organizations/uw-it-aca/settings/secrets:
#
# GH_AUTH_TOKEN: Grants access to private flux deployment repo
# GCP_JSON_KEY: Grants access to Google Cloud Registry
#
# To adapt this config file to a specific django project:
#
# 1) Set RELEASE_NAME suitable for deployment to k8s. RELEASE_NAME must
# match the "repo" value in docker/*-values.yml.
#
# 2) Set DJANGO_APP to the name of the django project name/directory.
#
# 3) Verify that the lists of branches for push/pull_request is appropriate,
# and add other branch names if needed. Additional branch names must
# also have steps defined in the deploy job
#
# 4) Confirm that the build steps are suitable. Likely they are, but
# some projects have an intermediate build step that could benefit
# from caching, so it may be useful to augment the build steps.
#
---
name: Build, Test and Deploy

env:
# Release name must match "repo" value in docker/*-values.yml
RELEASE_NAME: mdot
DJANGO_APP: mdot

# Be sure that branches defined here have corresponding steps
# defined in the "deploy" job
on:
push:
branches: [main, master, qa, develop, feature/eval-me]
branches: [main, develop]
pull_request:
branches: [main, master, qa, develop, feature/eval-me]
branches: [main, develop]
types: [opened, reopened, synchronize]

jobs:
Expand All @@ -62,25 +28,14 @@ jobs:
release_name: ${{ env.RELEASE_NAME }}

build:
runs-on: ubuntu-22.04
runs-on: ubuntu-20.04

needs: context

steps:
- name: Checkout Repo
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.10'

- name: Run Python Linters
uses: uw-it-aca/actions/python-linters@main
with:
app_name: ${DJANGO_APP}
exclude_paths: 'migrations'

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

Expand All @@ -93,44 +48,14 @@ jobs:
${{ runner.os }}-buildx-
- name: Build App Image
uses: docker/build-push-action@v6
uses: docker/build-push-action@v3
with:
context: .
target: app-container
tags: ${{ needs.context.outputs.image_tag }}
push: false
load: true
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache

- name: Build Test Image
uses: docker/build-push-action@v6
with:
target: app-test-container
tags: app-test-container
push: false
load: true

- name: Run Tests in Image
id: tests
shell: bash
run: >-
docker run -u root -t
-v ${PWD}:/coverage
-e DJANGO_APP="$DJANGO_APP"
-e "ENV=localdev" -e "AUTH=SAML_MOCK"
app-test-container
bash -c ". ./docker/test.sh"
- name: Record Test Results
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
shell: bash
run: |
python -m pip install --upgrade pip coverage coveralls==3.3.1
coverage combine
coveralls
- name: Push Image to Repository
if: github.event_name == 'push'
uses: uw-it-aca/actions/gcr-push@main
Expand All @@ -143,35 +68,25 @@ jobs:

needs: [context, build]

runs-on: ubuntu-22.04

outputs:
context: ${{ steps.context.outputs.context }}

runs-on: ubuntu-22.04

steps:
- name: Checkout Repo
uses: actions/checkout@v4

- name: Deployment Pipeline
if: >-
contains(fromJSON('["main", "master", "develop", "qa"]'),
contains(fromJSON('["main", "master"]'),
needs.context.outputs.git_repo_branch)
uses: uw-it-aca/actions/cicd-deploy@main
with:
release_name: ${{ env.RELEASE_NAME }}
commit_hash: ${{ needs.context.outputs.commit_hash }}
git_repo_branch: ${{ needs.context.outputs.git_repo_branch }}
gh_auth_token: ${{ secrets.GH_AUTH_TOKEN }}

- name: Deploy Evaluation Branch
if: needs.context.outputs.git_repo_branch == 'feature/eval-me'
uses: uw-it-aca/actions/cicd-deploy@main
with:
release_name: ${{ env.RELEASE_NAME }}
commit_hash: ${{ needs.context.outputs.commit_hash }}
git_repo_branch: ${{ needs.context.outputs.git_repo_branch }}
gh_auth_token: ${{ secrets.GH_AUTH_TOKEN }}
app_instance: eval

- name: 'Surface context from executed build step'
id: context
Expand All @@ -193,3 +108,4 @@ jobs:
gh_auth_token: ${{ secrets.GH_AUTH_TOKEN }}
registry_password: ${{ secrets.GCP_JSON_KEY }}
context: ${{ needs.deploy.outputs.context }}
prune_flux_preserve_count: 2
27 changes: 1 addition & 26 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,26 +1 @@
ARG DJANGO_CONTAINER_VERSION=2.0.3

FROM us-docker.pkg.dev/uwit-mci-axdd/containers/django-container:${DJANGO_CONTAINER_VERSION} AS app-container

USER root
RUN apt-get update && apt-get install libpq-dev -y
USER acait

ADD --chown=acait:acait . /app/
ADD --chown=acait:acait docker/ /app/project/
ADD --chown=acait:acait docker/app_start.sh /scripts
RUN chmod u+x /scripts/app_start.sh

RUN /app/bin/pip install -r requirements.txt
RUN /app/bin/pip install psycopg2

RUN . /app/bin/activate && pip install nodeenv && nodeenv -p &&\
npm install -g npm && ./bin/npm install less -g

RUN . /app/bin/activate && python manage.py collectstatic --noinput &&\
python manage.py compress -f

FROM us-docker.pkg.dev/uwit-mci-axdd/containers/django-test-container:${DJANGO_CONTAINER_VERSION} AS app-test-container

COPY --from=app-container /app/ /app/
COPY --from=app-container /static/ /static/
FROM us-docker.pkg.dev/uwit-mci-axdd/containers/nginx-container:1.1.2 AS app-container
3 changes: 0 additions & 3 deletions MANIFEST.in

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# MDOT APP #

[![Build Status](https://github.com/uw-it-aca/mdot/workflows/Build%2C%20Test%20and%20Deploy/badge.svg?branch=master)](https://github.com/uw-it-aca/mdot/actions)
[![Build Status](https://github.com/uw-it-aca/mdot/workflows/Build%2C%20Test%20and%20Deploy/badge.svg)](https://github.com/uw-it-aca/mdot/actions)
[![Coverage Status](https://coveralls.io/repos/github/uw-it-aca/mdot/badge.svg?branch=master)](https://coveralls.io/github/uw-it-aca/mdot?branch=master)

This README documents whatever steps are necessary to get your application up and running.
Expand Down
14 changes: 3 additions & 11 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,12 @@ version: '3.4'

services:
app:
environment:
PORT: 8000
restart: always
container_name: mdot
build:
context: .
dockerfile: ${DOCKERFILE:-Dockerfile}
target: app-container
# map the local (host) directories to their container counterparts
# to support live-syncing
volumes:
- ./mdot:/app/mdot
ports:
- "${PORT:-8000}:8000"
environment:
ENV: localdev
AUTH: ${AUTH:-SAML_MOCK}
RESTCLIENTS_MDOT_DAO_CLASS: ${RESTCLIENTS_MDOT_DAO_CLASS:-Mock}
RESTCLIENTS_MDOT_HOST: ${RESTCLIENTS_MDOT_HOST:-None}
- "${RUNSERVER_PORT:-8000}:8000"
Loading

0 comments on commit ddb117a

Please sign in to comment.