Skip to content

Commit

Permalink
Build docker image (#56)
Browse files Browse the repository at this point in the history
  • Loading branch information
lenguyenthanh authored Apr 25, 2024
2 parents 4b3fed3 + 55631cf commit d870f50
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 46 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Create and publish a Docker image
on:
push:
branches: ['main']
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
build-and-push-image:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Log in to the Container registry
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
- name: Build and push Docker image
run: sbt --client backend/Docker/publish
68 changes: 39 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,13 @@

Check [Open API docs](https://fide.thanh.se/docs/index.html)

## Examples

Get all players

```bash
curl 'fide.thanh.se/api/players'
```

Get top 10 players by standard rating with descending order

```bash
curl 'fide.thanh.se/api/players?sort_by=standard&order=desc&size=10'
```

Get all players sort by blitz rating and is active on page 5

```bash
curl 'fide.thanh.se/api/players?sort_by=blitz&order=desc&page=5&is_active=true'
```

## Development

### Prerequisites:

- Docker

### Run (with sbt locally)
### Run

Also requires JDK 21 with [sbt](https://www.scala-sbt.org/1.x/docs/Setup.html)

Expand All @@ -54,16 +34,10 @@ sbt backend/stage
export $(cat .env | xargs) && ./modules/backend/target/universal/stage/bin/backend
```

### Run (with sbt in Docker)

```bash
COMPOSE_PROFILES=sbt docker compose up -d
```

### Usage

```bash
open http://localhost:9669/docs // you may need to wait a bit for syncing
open http://localhost:9669/docs
curl http://localhost:9669/api/players
```

Expand All @@ -78,7 +52,7 @@ http://localhost:8180/?pgsql=db&username=admin&db=fide&ns=fide (password: dummy)

### Stress test with Gatling

Run [server](#run-with-sbt-locally) and then run Gatling
Run [server](#run) and then run Gatling

```bash
sbt gatling/gatling:test
Expand All @@ -90,3 +64,39 @@ sbt gatling/gatling:test
sbt test
sbt lint
```

## Run without building

You can use a pre-built Docker image from [GitHub Container Registry](https://github.com/lenguyenthanh/fide/pkgs/container/fide). Here is an example of how to run it with docker-compose:

```yaml
name: fide

services:

api:
image: ghcr.io/lenguyenthanh/fide:0.1.0-snapshot
env_file: .env.docker
ports:
- 9669:9669
networks:
- fide_api

db:
image: postgres:16.2-alpine3.19
ports:
- 5432:5432
networks:
- fide_api
restart: unless-stopped

networks:
fide_api:
driver: bridge
```
Then run:
```bash
docker compose up -d
```
8 changes: 5 additions & 3 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ inThisBuild(
organizationName := "Thanh Le",
licenses += ("agpl-v3" -> url("https://opensource.org/license/agpl-v3")),
semanticdbEnabled := true, // for scalafix
Compile / packageDoc / publishArtifact := false
Compile / packageDoc / publishArtifact := false,
dockerBaseImage := "openjdk:21"
)
)

Expand Down Expand Up @@ -94,15 +95,16 @@ lazy val backend = (project in file("modules/backend"))
Compile / run / fork := true,
Compile / run / connectInput := true,
Docker / dockerExposedPorts := Seq(9000, 9443),
Docker / packageName := "thanh/fide"
Docker / packageName := "lenguyenthanh/fide",
Docker / maintainer := "Thanh Le",
Docker / dockerRepository := Some("ghcr.io")
)
.enablePlugins(JavaAppPackaging, DockerPlugin)
.dependsOn(smithy, domain, db, crawler)

lazy val gatling = (project in file("modules/gatling"))
.settings(name := "gatling")
.enablePlugins(GatlingPlugin)
// .disablePlugins(ScalafixPlugin)
.settings(
scalacOptions -= "-Xfatal-warnings",
libraryDependencies ++= Seq(
Expand Down
14 changes: 0 additions & 14 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,6 @@ name: fide

services:

api:
image: sbtscala/scala-sbt:eclipse-temurin-jammy-21.0.2_13_1.9.9_3.4.1
volumes:
- .:/app
- .env.docker:/app/.env
working_dir: /app
entrypoint: sbt backend/run
ports:
- 9669:9669
networks:
- fide
profiles:
- sbt

db:
image: postgres:16.2-alpine3.19
container_name: fide_postgres
Expand Down

0 comments on commit d870f50

Please sign in to comment.