Skip to content

Commit

Permalink
build runner image
Browse files Browse the repository at this point in the history
  • Loading branch information
jamie-mh committed Oct 26, 2024
1 parent 5054b73 commit 350b9a0
Show file tree
Hide file tree
Showing 12 changed files with 303 additions and 212 deletions.
1 change: 1 addition & 0 deletions .github/workflows/develop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name: Build
on:
push:
branches:
- master
- develop
workflow_dispatch:

Expand Down
65 changes: 56 additions & 9 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
name: Build and Push
name: Build and Deploy

on:
push:
branches:
- master
workflow_dispatch:
tags:
- "v*"

env:
FRAMEWORK: net8.0
Expand Down Expand Up @@ -36,18 +35,66 @@ jobs:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Build and push PostGIS image
- name: Build and push Postgres image
uses: docker/build-push-action@v5
with:
push: true
context: docker/postgis
file: docker/postgis/Dockerfile
tags: ghcr.io/jamie-mh/estimmo-postgis:latest
context: docker/postgres
file: docker/postgres/Dockerfile
tags: ghcr.io/jamie-mh/estimmo-postgres:latest,ghcr.io/jamie-mh/estimmo-postgres:${{ github.ref_name }}

- name: Build and push API image
uses: docker/build-push-action@v5
with:
push: true
context: .
file: docker/api/Dockerfile
tags: ghcr.io/jamie-mh/estimmo-api:latest
tags: ghcr.io/jamie-mh/estimmo-api:latest,ghcr.io/jamie-mh/estimmo-api:${{ github.ref_name }}

- name: Build and push Runner image
uses: docker/build-push-action@v5
with:
push: true
context: .
file: docker/runner/Dockerfile
tags: ghcr.io/jamie-mh/estimmo-runner:latest,ghcr.io/jamie-mh/estimmo-runner:${{ github.ref_name }}

deploy:
runs-on: ubuntu-latest
needs: build

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

- name: Set up SSH
run: |
mkdir ~/.ssh
echo "${{ secrets.DEPLOY_KEY }}" > ~/.ssh/deploy.key
chmod 700 ~/.ssh
chmod 600 ~/.ssh/deploy.key
cat >>~/.ssh/config <<END
Host deploy
HostName ${{ secrets.DEPLOY_HOST }}
User ${{ secrets.DEPLOY_USER }}
IdentityFile ~/.ssh/deploy.key
StrictHostKeyChecking no
ControlMaster auto
ControlPath ~/.ssh/control-%C
ControlPersist yes
END
- name: Deploy
run: |
export DOCKER_HOST=ssh://deploy
echo ${{ secrets.GITHUB_TOKEN }} | docker login ghcr.io -u ${{ github.actor }} --password-stdin
# Deploy current tag
sed -i 's/estimmo-api:latest/estimmo-api:${{ github.ref_name }}/' compose.yaml
sed -i 's/estimmo-postgres:latest/estimmo-postgres:${{ github.ref_name }}/' compose.yaml
docker compose -f compose.yaml pull
docker compose -f compose.yaml down
docker compose -f compose.yaml up --no-deps -d
docker image prune -af
2 changes: 1 addition & 1 deletion Estimmo.Api/appsettings.Development.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
]
},
"ConnectionStrings": {
"Main": "Host=localhost;Port=8082;Database=estimmo;Username=estimmo;Password=estimmo;"
"Main": "Host=localhost;Port=5432;Database=estimmo;Username=estimmo;Password=estimmo;"
}
}
2 changes: 1 addition & 1 deletion Estimmo.Api/appsettings.Production.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@
]
},
"ConnectionStrings": {
"Main": "Host=postgis;Port=5432;Database=estimmo;Username=estimmo;Password=estimmo;"
"Main": "Host=postgres;Port=5432;Database=estimmo;Username=estimmo;Password=estimmo;"
}
}
2 changes: 1 addition & 1 deletion Estimmo.Runner/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@
]
},
"ConnectionStrings": {
"Main": "Host=localhost;Port=8082;Database=estimmo;Username=estimmo;Password=estimmo;CommandTimeout=0;IncludeErrorDetail=true"
"Main": "Host=postgres;Port=5432;Database=estimmo;Username=estimmo;Password=estimmo;CommandTimeout=0;IncludeErrorDetail=true"
}
}
22 changes: 0 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,6 @@ High-performance French real-estate estimation and history API built with ASP.NE

[API Documentation](https://estimmo-api.jmh.me/swagger)

## Running

No data is provided and must be downloaded and imported.

### Requirements

- .NET 8
- PostgreSQL 14+ database with PostGIS and tdigest extensions
- cURL
- gzip
- Mapshaper

### Generating the database

Update the `appsettings.[env].json` files as required.

The init script will download the required data and process it.

```
./init.sh
```

## Data sources

- [France GeoJSON](https://github.com/gregoiredavid/france-geojson)
Expand Down
17 changes: 17 additions & 0 deletions compose.dev.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
services:
postgres:
build: docker/postgis
shm_size: 2g
container_name: estimmo-postgres
volumes:
- db-data:/var/lib/postgresql/data
ports:
- "5432:5432"
environment:
- POSTGRES_USER=estimmo
- POSTGRES_PASSWORD=estimmo
- POSTGRES_DB=estimmo

volumes:
db-data:
driver: local
45 changes: 39 additions & 6 deletions compose.yaml
Original file line number Diff line number Diff line change
@@ -1,18 +1,51 @@
version: "3.1"
services:
api:
container_name: estimmo-api
image: ghcr.io/jamie-mh/estimmo-api:latest
restart: always
ports:
- 8081:8080
environment:
- DOTNET_ENVIRONMENT=Production
depends_on:
postgres:
condition: service_healthy
networks:
- estimmo
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8080/api/health"]
interval: 30s
timeout: 10s
retries: 10
start_interval: 10s
start_period: 30s

postgres:
build: docker/postgis
shm_size: 2g
container_name: estimmo-postgres
image: ghcr.io/jamie-mh/estimmo-postgres:latest
restart: always
shm_size: 2g
volumes:
- db-data:/var/lib/postgresql/data
ports:
- "8082:5432"
networks:
- estimmo
environment:
- POSTGRES_USER=estimmo
- POSTGRES_PASSWORD=estimmo
- PG_USER=estimmo
- POSTGRES_DB=estimmo
- POSTGRES_PASSWORD=estimmo
healthcheck:
test: ["CMD-SHELL", "pg_isready"]
interval: 30s
timeout: 5s
retries: 10
start_interval: 5s
start_period: 30s

volumes:
db-data:
driver: local

networks:
estimmo:
driver: bridge
File renamed without changes.
14 changes: 14 additions & 0 deletions docker/runner/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM mcr.microsoft.com/dotnet/runtime:8.0-noble
LABEL org.opencontainers.image.source=https://github.com/jamie-mh/estimmo-api

RUN apt-get update && apt-get install -y curl nodejs npm
RUN npm install -g mapshaper

WORKDIR /app
COPY Estimmo.Runner/bin/Release/net8.0/linux-x64/publish /app
COPY docker/runner/entrypoint.sh /app

RUN mkdir /data
VOLUME /data

ENTRYPOINT ["/app/entrypoint.sh"]
Loading

0 comments on commit 350b9a0

Please sign in to comment.