Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:

strategy:
matrix:
python-version: [3.7, 3.8]
python-version: [3.9]

steps:
- name: Install ldap dependencies
Expand Down
11 changes: 8 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
FROM python:3.7-slim-buster
FROM python:3.9-slim-buster
MAINTAINER Devin Matte <[email protected]>

ENV DD_LOGS_INJECTION=true

RUN apt-get -yq update && \
apt-get -yq --no-install-recommends install gcc curl libsasl2-dev libldap2-dev libssl-dev gnupg2 && \
apt-get -yq --no-install-recommends install gcc curl libsasl2-dev libldap2-dev libssl-dev gnupg2 git && \
apt-get -yq clean all

RUN mkdir /opt/packet
Expand Down Expand Up @@ -30,4 +32,7 @@ RUN curl -sL https://deb.nodesource.com/setup_10.x | bash - && \

RUN ln -sf /usr/share/zoneinfo/America/New_York /etc/localtime

CMD ["ddtrace-run", "gunicorn", "packet:app", "--bind=0.0.0.0:8080", "--access-logfile=-", "--timeout=600"]
# Set version for apm
RUN echo "export DD_VERSION=$(python3 packet/git.py)" >> /tmp/version

CMD ["/bin/bash", "-c", "source /tmp/version && ddtrace-run gunicorn packet:app --bind=0.0.0.0:8080 --access-logfile=- --timeout=600"]
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# CSH Web Packet

[![Python 3.7](https://img.shields.io/badge/python-3.7-blue.svg)](https://www.python.org/downloads/release/python-370/)
[![Python 3.9](https://img.shields.io/badge/python-3.9-blue.svg)](https://www.python.org/downloads/release/python-390/)
[![Build Status](https://travis-ci.com/ComputerScienceHouse/packet.svg?branch=develop)](https://travis-ci.com/ComputerScienceHouse/packet)

Packet is used by CSH to facilitate the freshmen packet portion of our introductory member evaluation process. This is
the second major iteration of packet on the web. The first version was
[Tal packet](https://github.com/TalCohen/CSHWebPacket).

## Setup
**Requires Python 3.7 or newer.**
**Requires Python 3.9 or newer.**

To get the server working you'll just need the Python dependencies and some secrets. There will be some UI issues due
to missing assets though. To solve that you'll want to set up the front end dependencies or download a copy of the
Expand Down
7 changes: 4 additions & 3 deletions packet/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
from sentry_sdk.integrations.flask import FlaskIntegration
from sentry_sdk.integrations.sqlalchemy import SqlalchemyIntegration

from .git import get_version

app = Flask(__name__)
gzip = Gzip(app)

Expand All @@ -31,9 +33,8 @@
if os.path.exists(_pyfile_config):
app.config.from_pyfile(_pyfile_config)

# Fetch the version number from the npm package file
with open(os.path.join(_root_dir, 'package.json')) as package_file:
app.config['VERSION'] = json.load(package_file)['version']
# Fetch the version number
app.config['VERSION'] = get_version()

# Logger configuration
logging.getLogger().setLevel(app.config['LOG_LEVEL'])
Expand Down
49 changes: 49 additions & 0 deletions packet/git.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import json
import os
import subprocess

def get_short_sha(commit_ish: str = 'HEAD'):
"""
Get the short hash of a commit-ish
Returns '' if unfound
"""

try:
rev_parse = subprocess.run(f'git rev-parse --short {commit_ish}'.split(), capture_output=True, check=True)
return rev_parse.stdout.decode('utf-8').strip()
except subprocess.CalledProcessError:
return ''

def get_tag(commit_ish: str = 'HEAD'):
"""
Get the name of the tag at a given commit-ish
Returns '' if untagged
"""

try:
describe = subprocess.run(f'git describe --exact-match {commit_ish}'.split(), capture_output=True, check=True)
return describe.stdout.decode('utf-8').strip()
except subprocess.CalledProcessError:
return ''

def get_version(commit_ish: str = 'HEAD'):
"""
Get the version string of a commit-ish

If we have a commit and the commit is tagged, version is `tag (commit-sha)`
If we have a commit but not a tag, version is `commit-sha`
If we have neither, version is the version field of package.json
"""

if sha := get_short_sha(commit_ish):
if tag := get_tag(commit_ish):
return f'{tag} ({sha})'
else:
return sha
else:
root_dir = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
with open(os.path.join(root_dir, 'package.json')) as package_file:
return json.load(package_file)['version']

if __name__ == '__main__':
print(get_version())