Skip to content

Commit

Permalink
Merge pull request #16 from sun-yryr/feature/new-async-await
Browse files Browse the repository at this point in the history
async/await対応ともうなんか全部
  • Loading branch information
sun-yryr authored Jan 8, 2024
2 parents 6b99ee1 + 9483f81 commit a9095e0
Show file tree
Hide file tree
Showing 24 changed files with 630 additions and 400 deletions.
2 changes: 1 addition & 1 deletion .env.testing
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
DATABASE_HOST=127.0.0.1
DATABASE_PORT=3306
DATABASE_PORT=5432
DATABASE_USERNAME=vapor_username
DATABASE_PASSWORD=vapor_password
DATABASE_NAME=test_agqr_program_guide
9 changes: 5 additions & 4 deletions .github/workflows/build-push.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
name: build-push
run-name: Push [${{ inputs.version }}] from ${{ github.ref_name }}

on:
workflow_dispatch:
Expand All @@ -12,18 +13,18 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v1.5.1
uses: docker/setup-buildx-action@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v1
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v2
uses: docker/build-push-action@v5
with:
push: true
tags: ghcr.io/${{ github.repository }}:${{ github.event.inputs.version }}
34 changes: 34 additions & 0 deletions .github/workflows/check-openapi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Check OpenAPI
on:
push:
branches:
- master
paths:
- '.github/workflows/check-openapi.yaml'
- 'reference/agqr-radio-program-guide-api.v2.yaml'
- 'Resources/Views/redoc-static.html'
pull_request:
branches:
- master
paths:
- '.github/workflows/check-openapi.yaml'
- 'reference/agqr-radio-program-guide-api.v2.yaml'
- 'Resources/Views/redoc-static.html'

jobs:
exists-diff:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: make generate-redoc
- name: Check exists diff
run: |
if ! git diff --quiet; then
exit 1
fi
# TODO: 後で直す
# lint:
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v4
# - run: make lint-openapi
21 changes: 17 additions & 4 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,23 @@ on:
- master

jobs:
setup:
runs-on: macos-latest
build:
name: Swift ${{ matrix.swift }} on ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest]
swift: ["5.9"]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- uses: swift-actions/setup-swift@v1
with:
swift-version: ${{ matrix.swift }}
- uses: actions/checkout@v4
- run: swift package resolve
- name: swift test
- name: Build
run: swift build
- name: setup service
run: |
docker compose up -d db --wait
- name: Run tests
run: swift test
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,4 @@ EXPOSE 8080

# Start the Vapor service when the image is run, default to listening on 8080 in production environment
ENTRYPOINT ["./Run"]
CMD ["serve", "--env", "production", "--hostname", "0.0.0.0", "--port", "8080"]
CMD ["serve", "--env", "production", "--hostname", "0.0.0.0", "--port", "8080"]
7 changes: 6 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ migrate:
build:
docker-compose build --no-cache
up:
docker-compose up -d db redis
docker-compose up -d db
down:
docker-compose down

.PHONY: generate-redoc
generate-redoc:
docker run --rm -v ${PWD}/reference:/spec redocly/cli build-docs agqr-radio-program-guide-api.v2.yaml -o redoc-static.html
mv reference/redoc-static.html Resources/Views/redoc-static.html
69 changes: 21 additions & 48 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@
}
},
{
"package": "fluent-mysql-driver",
"repositoryURL": "https://github.com/vapor/fluent-mysql-driver.git",
"package": "fluent-postgres-driver",
"repositoryURL": "https://github.com/vapor/fluent-postgres-driver.git",
"state": {
"branch": null,
"revision": "f86bf9c80a1c176234a16796c19add399a266c38",
"version": "4.0.2"
"revision": "7c266b539f71331ad6e53ea8fae587ccdaf972f2",
"version": "2.2.6"
}
},
{
Expand Down Expand Up @@ -92,57 +92,21 @@
}
},
{
"package": "mysql-kit",
"repositoryURL": "https://github.com/vapor/mysql-kit.git",
"package": "postgres-kit",
"repositoryURL": "https://github.com/vapor/postgres-kit.git",
"state": {
"branch": null,
"revision": "f54e0876fce2d68551be0e704b3a94f78eedb9f8",
"version": "4.5.0"
"revision": "35deea5c28a7d402f3280d81dee37bed5c56b9fe",
"version": "2.8.3"
}
},
{
"package": "mysql-nio",
"repositoryURL": "https://github.com/vapor/mysql-nio.git",
"package": "postgres-nio",
"repositoryURL": "https://github.com/vapor/postgres-nio.git",
"state": {
"branch": null,
"revision": "f0e8ad7e18e870e8665311d70bf3f01dcd6024a8",
"version": "1.4.0"
}
},
{
"package": "queues",
"repositoryURL": "https://github.com/vapor/queues.git",
"state": {
"branch": null,
"revision": "58b2d785118d164b38c59beb595cbffbea7608ef",
"version": "1.8.1"
}
},
{
"package": "queues-redis-driver",
"repositoryURL": "https://github.com/vapor/queues-redis-driver.git",
"state": {
"branch": null,
"revision": "2728477b50e24be82f5bc0bd0722c35656e1c5b1",
"version": "1.0.3"
}
},
{
"package": "redis",
"repositoryURL": "https://github.com/vapor/redis.git",
"state": {
"branch": null,
"revision": "e955843b08064071f465a6b1ca9e04bebad8623a",
"version": "4.6.0"
}
},
{
"package": "RediStack",
"repositoryURL": "https://gitlab.com/mordil/RediStack.git",
"state": {
"branch": null,
"revision": "5458d6476e05d5f1b43097f1bc9b599e936b5f2f",
"version": "1.3.0"
"revision": "d648c5b4594ffbc2f6173318f70f5531e05ccb4e",
"version": "1.11.0"
}
},
{
Expand All @@ -163,6 +127,15 @@
"version": "3.18.0"
}
},
{
"package": "swift-atomics",
"repositoryURL": "https://github.com/apple/swift-atomics.git",
"state": {
"branch": null,
"revision": "cd142fd2f64be2100422d658e7411e39489da985",
"version": "1.2.0"
}
},
{
"package": "swift-backtrace",
"repositoryURL": "https://github.com/swift-server/swift-backtrace.git",
Expand Down
12 changes: 4 additions & 8 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
// swift-tools-version:5.2
// swift-tools-version:5.5
import PackageDescription

let package = Package(
name: "agqr-program-guide",
platforms: [
.macOS(.v10_15)
.macOS(.v12)
],
dependencies: [
// 💧 A server-side Swift web framework.
.package(url: "https://github.com/vapor/vapor.git", from: "4.0.0"),
.package(url: "https://github.com/vapor/fluent.git", from: "4.0.0"),
.package(url: "https://github.com/vapor/fluent-mysql-driver.git", from: "4.0.0"),
.package(url: "https://github.com/vapor/fluent-postgres-driver.git", from: "2.0.0"),
.package(url: "https://github.com/vapor/leaf.git", from: "4.0.0"),
.package(url: "https://github.com/vapor/redis.git", from: "4.0.0"),
.package(url: "https://github.com/vapor/queues-redis-driver.git", from: "1.0.0"),
// HTML Parser
.package(url: "https://github.com/tid-kijyun/Kanna.git", .upToNextMajor(from: "5.2.4"))
],
Expand All @@ -22,10 +20,8 @@ let package = Package(
name: "App",
dependencies: [
.product(name: "Fluent", package: "fluent"),
.product(name: "FluentMySQLDriver", package: "fluent-mysql-driver"),
.product(name: "FluentPostgresDriver", package: "fluent-postgres-driver"),
.product(name: "Leaf", package: "leaf"),
.product(name: "Redis", package: "redis"),
.product(name: "QueuesRedisDriver", package: "queues-redis-driver"),
.product(name: "Vapor", package: "vapor"),
.product(name: "Kanna", package: "Kanna"),

Expand Down
59 changes: 2 additions & 57 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,62 +1,7 @@
# agqr-program-guide

[超A&G+の番組表](https://www.joqr.co.jp/qr/agdailyprogram/) から番組情報・出演者を取得し、JSON形式のREST APIとして提供しています
[超A&G+の番組表](https://www.joqr.co.jp/qr/agdailyprogram/) から番組情報・出演者を取得し、JSON 形式の REST API として提供しています

https://agqr.sun-yryr.com で提供中です。

フレームワークとしてSwift製のVaporを利用しています。

## Development

前提
```bash
swift --version
# 5.4.2
vapor --version
# framework: 4.45.0
# toolbox: 18.3.3
```

1. DBとRedisを起動する。 `make up`
1. 開発する。
1. サーバーを立てて動作確認する。 `make serve`

### lint

swiftlintかswift-formatを利用する予定。更新する。

### build & push

GitHub Actionsのページから `build-push` のワークフローを実行する。

### deploy

1. EC2にログインする。
1. pushしたDockerImageをPullしてくる。(直接起動する場合は飛ばしてもいい)
1. 環境変数とかを設定して起動する。下記の「使う」を参考にする。

## 使う

適宜タグや環境変数の変更が必要。

### マイグレーション
```bash
docker run --rm -e DATABASE_HOST=127.0.0.1 -e REDIS_URL="redis://127.0.0.1:6379" ghcr.io/sun-yryr/agqr-program-guide:latest migrate --yes
```

### 手動スクレイピング

基本的に自動で取ってくるので必要ない。初回起動などで利用する。
※ hoge は使っていない引数なので後々削除する。
```bash
docker run --rm -e DATABASE_HOST=127.0.0.1 -e REDIS_URL="redis://127.0.0.1:6379" -e TZ=Asia/Tokyo ghcr.io/sun-yryr/agqr-program-guide:latest scraping hoge
```

### 起動
```bash
docker run -d -e DATABASE_HOST=127.0.0.1 -e REDIS_URL="redis://127.0.0.1:6379" -e TZ=Asia/Tokyo -p 3000:8080 ghcr.io/sun-yryr/agqr-program-guide:latest
```

## ライセンス

そのうち
フレームワークとして [Vapor](https://github.com/vapor/vapor) を利用しています。
Loading

0 comments on commit a9095e0

Please sign in to comment.