Skip to content

Commit 856a9b7

Browse files
feat: add Containerfile to repo
adds a Containerfile so folks can develop with a container also adds instructions to README and CI job to ensure Containerfile doesn't get broken Signed-off-by: Nathan Weinberg <nathansweinberg@gmail.com>
1 parent 509540b commit 856a9b7

File tree

4 files changed

+128
-0
lines changed

4 files changed

+128
-0
lines changed

.dockerignore

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# production
2+
build
3+
data
4+
output
5+
6+
# python
7+
__pycache__
8+
.pytest_cache
9+
.venv
10+
.poetry
11+
12+
# misc
13+
.DS_Store
14+
15+
# config
16+
config/local.json
17+
.envrc
18+
19+
# logs
20+
gobble.log
21+
s3_upload.log

.github/workflows/container.yml

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
name: container
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- Containerfile
7+
push:
8+
branches:
9+
- main
10+
11+
jobs:
12+
build:
13+
runs-on: ubuntu-latest
14+
env:
15+
MBTA_V3_API_KEY: ${{ secrets.MBTA_V3_API_KEY }}
16+
steps:
17+
- name: Checkout repo
18+
uses: actions/checkout@v3
19+
20+
- name: Set up Docker Buildx
21+
uses: docker/setup-buildx-action@v3
22+
23+
- name: Build container image
24+
uses: docker/build-push-action@v6
25+
with:
26+
context: .
27+
file: ./Containerfile
28+
push: false
29+
tags: gobble:test
30+
load: true
31+
cache-from: type=gha
32+
cache-to: type=gha,mode=max
33+
build-args: |
34+
GIT_ABR_VERSION=${{ github.sha }}
35+
36+
- name: Create config file
37+
run: |
38+
cat >> ./local.json << EOF
39+
{
40+
"mbta": {
41+
"v3_api_key": "${{ secrets.MBTA_V3_API_KEY }}"
42+
},
43+
"modes": ["cr", "bus"],
44+
"gtfs": {
45+
"refresh_interval_days": 7
46+
},
47+
"DATADOG_TRACE_ENABLED": true
48+
}
49+
50+
- name: Test container starts successfully
51+
run: |
52+
# Start the container in the background
53+
docker run -d \
54+
-v ./config/local.json:/app/config/local.json:z \
55+
-v ./data:/app/data:z \
56+
--name gobble \
57+
gobble:test
58+
59+
# Wait for the container to start
60+
sleep 10
61+
62+
# Check if container is still running
63+
if ! docker ps | grep -q gobble; then
64+
echo "Container failed to start"
65+
docker logs gobble
66+
exit 1
67+
fi
68+
69+
# Check if there are any files in data directory
70+
find data -type f -print -quit || exit 1
71+
72+
# Cleanup
73+
docker stop gobble
74+
docker rm gobble

Containerfile

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
FROM python:3.12-slim
2+
3+
WORKDIR /app
4+
5+
# Install uv for Python dependency management
6+
COPY --from=ghcr.io/astral-sh/uv:latest /uv /usr/local/bin/uv
7+
8+
# Copy source code
9+
COPY . .
10+
11+
# Install dependencies
12+
RUN uv sync
13+
14+
# Set environment variables
15+
ENV PYTHONUNBUFFERED=1
16+
ENV PYTHONPATH=/app/src
17+
18+
ENTRYPOINT ["uv", "run", "python3", "src/gobble.py"]

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# gobble
22
![lint](https://github.com/transitmatters/gobble/actions/workflows/lint.yml/badge.svg?branch=main)
33
![test](https://github.com/transitmatters/gobble/actions/workflows/test.yml/badge.svg?branch=main)
4+
![deploy](https://github.com/transitmatters/gobble/actions/workflows/deploy.yml/badge.svg?branch=main)
45

56
![Screenshot in action](docs/screenshot.png)
67

@@ -18,6 +19,20 @@ Gobble is a service that reads the [MBTA V3 Streaming API](https://www.mbta.com/
1819
3. Run `uv run src/gobble.py` to start.
1920
4. Output will be in `data/` in your current working directory. Good luck!
2021

22+
### Container
23+
24+
You can also run Gobble inside a container using the following `docker build` and `docker run` commands
25+
26+
```bash
27+
docker build -t gobble -f Containerfile .
28+
docker run \
29+
-v ./config/local.json:/app/config/local.json:z \
30+
-v ./data:/app/data:z \
31+
gobble:latest
32+
```
33+
34+
Output will be in `data/` in your current working directory. Good luck!
35+
2136
### Linting
2237

2338
You can run the linter against any code changes with the following commands

0 commit comments

Comments
 (0)