Skip to content

Commit 79a2113

Browse files
authored
Merge pull request #31 from midwire/add-dockerfile
Add Dockerfile for containerized data generation
2 parents e44af09 + 5548d87 commit 79a2113

4 files changed

Lines changed: 80 additions & 0 deletions

File tree

.dockerignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.git
2+
vendor/bundle
3+
pkg
4+
stubs
5+
spec
6+
data
7+
build
8+
.claude
9+
docs
10+
*.sqlite3

Dockerfile

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
FROM ruby:3.4-slim
2+
3+
RUN apt-get update && \
4+
apt-get install -y --no-install-recommends build-essential git pkg-config && \
5+
rm -rf /var/lib/apt/lists/*
6+
7+
WORKDIR /app
8+
9+
COPY Gemfile Gemfile.lock free_zipcode_data.gemspec .ruby-version ./
10+
COPY lib/free_zipcode_data/version.rb lib/free_zipcode_data/version.rb
11+
RUN git init && git add . && \
12+
bundle config set --local without development && \
13+
bundle install
14+
15+
COPY . .
16+
RUN git add .
17+
18+
ENV COUNTRY=""
19+
VOLUME /output
20+
21+
ENTRYPOINT ["./docker-entrypoint.sh"]

README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,41 @@ create table zipcodes (
105105
106106
Both `lat` and `lon`, geocodes, are populated for each zipcode record.
107107
108+
## Docker
109+
110+
If you prefer not to install Ruby locally, you can use Docker to generate the database. You only need [Docker](https://docs.docker.com/get-docker/) installed.
111+
112+
### Build the image
113+
114+
```bash
115+
$ git clone https://github.com/midwire/free_zipcode_data.git
116+
$ cd free_zipcode_data
117+
$ docker build -t free_zipcode_data .
118+
```
119+
120+
### Generate data
121+
122+
Use the `COUNTRY` environment variable to specify a 2-letter country code. Omit it to process all available countries.
123+
124+
**Single country (e.g., US):**
125+
126+
```bash
127+
$ docker run --rm -v $(pwd)/output:/output -e COUNTRY=US free_zipcode_data
128+
```
129+
130+
**All countries:**
131+
132+
```bash
133+
$ docker run --rm -v $(pwd)/output:/output free_zipcode_data
134+
```
135+
136+
The following files will be written to the `./output/` directory on your host:
137+
138+
* `free_zipcode_data.sqlite3` - SQLite database with countries, states, counties, and zipcodes tables
139+
* `countries.csv`, `states.csv`, `counties.csv`, `zipcodes.csv` - CSV exports of each table
140+
141+
Look up supported country codes at [GeoNames](http://download.geonames.org/export/zip/).
142+
108143
## Data License
109144
110145
The zipcode data is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by/3.0/">Creative Commons Attribution 3.0 Unported License</a>, carried forward from [GeoNames](http://www.geonames.org).<br />

docker-entrypoint.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
args=(--work-dir /output --generate-files --clobber)
5+
6+
if [ -n "${COUNTRY:-}" ]; then
7+
if [[ ! "$COUNTRY" =~ ^[A-Z]{2}$ ]]; then
8+
echo "Error: COUNTRY must be a 2-letter uppercase code (e.g., US, AD)" >&2
9+
exit 1
10+
fi
11+
args+=(--country "$COUNTRY")
12+
fi
13+
14+
exec bundle exec ruby bin/free_zipcode_data "${args[@]}"

0 commit comments

Comments
 (0)