Skip to content

Commit ba5c7ae

Browse files
authored
Merge pull request #1 from netz39/project-setup
Project setup
2 parents 34422c0 + 4d7898e commit ba5c7ae

File tree

13 files changed

+364
-0
lines changed

13 files changed

+364
-0
lines changed

.env.template

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
PORT=8080

.github/workflows/docker-image.yml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
name: Docker Image
2+
3+
on:
4+
push:
5+
branches:
6+
- 'main'
7+
tags:
8+
- 'v*'
9+
pull_request:
10+
branches:
11+
- 'main'
12+
13+
jobs:
14+
docker:
15+
runs-on: ubuntu-latest
16+
17+
env:
18+
IMAGE_NAME: spaceapi-service
19+
20+
steps:
21+
- name: Checkout
22+
uses: actions/checkout@v4
23+
with:
24+
ref: ${{ github.ref }}
25+
# Needed for correct version detection
26+
fetch-depth: 0
27+
28+
- name: Docker meta
29+
id: meta
30+
uses: docker/metadata-action@v3
31+
with:
32+
images: ${{ secrets.DOCKERHUB_USERNAME }}/${{ env.IMAGE_NAME }}
33+
tags: |
34+
# 1.2.3
35+
type=semver,pattern={{version}}
36+
# disabled if major zero
37+
type=semver,pattern={{major}},enable=${{ !startsWith(github.ref, 'refs/tags/v0.') }}
38+
# generate lates from default branch
39+
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', github.event.repository.default_branch) }}
40+
41+
- name: Set up QEMU
42+
uses: docker/setup-qemu-action@v1
43+
44+
- name: Set up Docker Buildx
45+
uses: docker/setup-buildx-action@v1
46+
47+
- name: Login to DockerHub
48+
if: github.event_name != 'pull_request'
49+
uses: docker/login-action@v1
50+
with:
51+
username: ${{ secrets.DOCKERHUB_USERNAME }}
52+
password: ${{ secrets.DOCKERHUB_TOKEN }}
53+
54+
- name: Build and push
55+
uses: docker/build-push-action@v2
56+
with:
57+
context: .
58+
platforms: linux/amd64,linux/arm64,linux/arm/v7
59+
push: ${{ github.event_name != 'pull_request' }}
60+
tags: ${{ steps.meta.outputs.tags }}
61+
labels: ${{ steps.meta.outputs.labels }}

.github/workflows/pytest.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: PyTest
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Checkout repository
14+
uses: actions/checkout@v3
15+
16+
- name: Install python
17+
uses: actions/setup-python@v5
18+
with:
19+
python-version: '3.12'
20+
21+
- name: Install dependencies
22+
run: |
23+
python -m pip install --upgrade pip
24+
pip install -r requirements.txt
25+
26+
- name: Run tests with pytest
27+
run: pytest --verbose

.github/workflows/release.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Create Release
2+
3+
on:
4+
push:
5+
tags:
6+
- "v*"
7+
8+
jobs:
9+
build:
10+
name: "Release"
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: "Check-out"
14+
uses: actions/checkout@v3
15+
with:
16+
fetch-depth: 0
17+
- name: "Generate release changelog"
18+
id: generate-release-changelog
19+
uses: heinrichreimer/github-changelog-generator-action@v2.3
20+
with:
21+
token: ${{ secrets.GITHUB_TOKEN }}
22+
onlyLastTag: "true" # set to false if no tags exist (buggy with only one tag)
23+
stripHeaders: "true"
24+
stripGeneratorNotice: "true"
25+
- name: Extract the VERSION name
26+
id: get-version
27+
run: echo ::set-output name=VERSION::${GITHUB_REF#refs/tags/}
28+
- name: "Create GitHub release"
29+
uses: softprops/action-gh-release@v1
30+
with:
31+
tag_name: ${{ github.ref }}
32+
name: "${{ steps.get-version.outputs.VERSION }}"
33+
body: "${{ steps.generate-release-changelog.outputs.changelog }}"
34+
prerelease: ${{ startsWith(steps.get-version.outputs.VERSION, 'v0.') }}
35+
token: ${{ secrets.GITHUB_TOKEN }}
36+
draft: True

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.env
2+
3+
.idea
4+
venv/

Dockerfile

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
FROM alpine/git AS install
2+
3+
# If the --dirty flag is left out, only the .git directory has to be copied
4+
ADD . /git/
5+
RUN git describe --always --dirty > /git-version.txt
6+
7+
8+
FROM python:3.12
9+
10+
EXPOSE 8080
11+
HEALTHCHECK --interval=10s CMD curl --fail http://localhost:8080/v0/health || exit 1
12+
13+
COPY src/OAS3.yml /
14+
15+
COPY requirements.txt /
16+
RUN pip install -r requirements.txt
17+
18+
COPY src/*.py /
19+
20+
COPY --from=install /git-version.txt /
21+
22+
CMD ["python", "-u", "./app.py"]

README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,41 @@
22

33
> Microservice to provide the [Space API](https://spaceapi.io/) JSON from our MQTT topic status.
44
5+
## Usage
6+
7+
### Configuration
8+
9+
Configuration is done using environment variables:
10+
11+
* `PORT`: Target port when used with docker-compose (default `8080`)
12+
13+
### Run with Docker
14+
15+
```bash
16+
docker run --rm -it \
17+
-p 8080:8080 \
18+
netz39/spaceapi-service
19+
```
20+
21+
### Run with Docker-Compose (Development)
22+
23+
To run with [docker-compose](https://docs.docker.com/compose/) copy [`.env.template`](.env.template) to `.env` and edit the necessary variables. Then start with:
24+
25+
```bash
26+
docker-compose up --build
27+
```
28+
29+
Please note that this compose file will rebuild the image based on the repository. This is helpful during development and not intended for production use.
30+
31+
When done, please don't forget to remove the deployment with
32+
```bash
33+
docker-compose down
34+
```
35+
36+
## Maintainers
37+
38+
* Stefan Haun ([@penguineer](https://github.com/penguineer))
39+
540

641
## License
742

docker-compose.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Do not forget to create the .env file (see template)
2+
# before using this container!
3+
4+
version: '2'
5+
6+
services:
7+
collector:
8+
restart: always
9+
build: .
10+
environment:
11+
PORT: 8080
12+
ports:
13+
- $PORT:8080
14+
15+
volumes:
16+
db:

pytest.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[pytest]
2+
asyncio_mode = strict
3+
pythonpath = "src/"

requirements.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
pytest==7.1.2
2+
pytest-asyncio==0.19.0
3+
tornado==6.4.1
4+
isodate==0.6.0

0 commit comments

Comments
 (0)