diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 22d9e9a..6107258 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -1,17 +1,14 @@ name: Build image on: - push: - branches: - - main - pull_request: + workflow_call: # temporarily disable concurrency: group: ${{ github.workflow }}-${{ github.ref }} env: REGISTRY: ghcr.io # Only used for labeling, if you want to push it make sure you have permissions to push. - IMAGE_NAME: ${{ github.repository }} + IMAGE_NAME: kbluescode/dumbkv jobs: build-image: @@ -20,8 +17,12 @@ jobs: permissions: contents: read + # https://github.com/marketplace/actions/build-and-push-docker-images steps: - - name: Checkout - uses: actions/checkout@v4 - - # TODO: Maybe there's an action that does this for us. \ No newline at end of file + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - name: Build and push + uses: docker/build-push-action@v6 + with: + push: false + tags: ${{ env.IMAGE_NAME }} diff --git a/.github/workflows/cicd.yaml b/.github/workflows/cicd.yaml new file mode 100644 index 0000000..badb5c1 --- /dev/null +++ b/.github/workflows/cicd.yaml @@ -0,0 +1,39 @@ +name: CICD + +on: + pull_request: + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + +env: + REGISTRY: ghcr.io # Only used for labeling, if you want to push it make sure you have permissions to push. + IMAGE_NAME: kbluescode/dumbkv + +jobs: + build-image: + runs-on: ubuntu-latest + + permissions: + contents: read + + # https://github.com/marketplace/actions/build-and-push-docker-images + steps: + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - name: Build and push + uses: docker/build-push-action@v6 + with: + push: false + tags: ${{ env.IMAGE_NAME }} + + test-image: + needs: build-image + runs-on: ubuntu-latest + permissions: + contents: read + + if: github.event_name == 'pull_request' + steps: + - name: Run pytest + run: docker run --rm -it kbluescode/dumbkv:latest uv run python -m pytest diff --git a/.tool-versions b/.tool-versions new file mode 100644 index 0000000..722467c --- /dev/null +++ b/.tool-versions @@ -0,0 +1 @@ +python 3.12.11 diff --git a/Dockerfile b/Dockerfile index 82f7938..f83bfbb 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,4 +8,9 @@ RUN apt-get update && apt-get upgrade -y && apt-get install -y --no-install-reco RUN uv python install 3.12 -# TODO: Install the python packages and run uvicorn \ No newline at end of file +COPY . /app + +RUN uv sync + +ENV HOST="0.0.0.0" PORT="8000" LOG_CONFIG="logging.yaml" +CMD uv run uvicorn main:api --host $HOST --port $PORT --log-config $LOG_CONFIG diff --git a/README.md b/README.md index c193d10..b591174 100644 --- a/README.md +++ b/README.md @@ -110,4 +110,4 @@ The manifests can be saved in a `manifests` directory. ## Monitoring - [ ] Create a service monitor objects for prometheus to scrape the metrics -- [ ] Create a markdown document describing what SLO you would set for this application \ No newline at end of file +- [ ] Create a markdown document describing what SLO you would set for this applicationhi diff --git a/justfile b/justfile new file mode 100644 index 0000000..71c0687 --- /dev/null +++ b/justfile @@ -0,0 +1,29 @@ +# https://just.systems + +_default: + @just --list + +HOST := '0.0.0.0' +PORT := '8000' +LOG_CONFIG := 'logging.yaml' + +run: + uv run uvicorn main:api --host {{HOST}} --port {{PORT}} --log-config {{LOG_CONFIG}} + +[group('docker')] +build: + docker build -t kbluescode/dumbkv . + +[group('docker')] +run-image: + docker run --rm -it -p {{PORT}}:{{PORT}} kbluescode/dumbkv + +[group('testing')] +test: + uv run python -m pytest + +DATABASE_URI := 'postgres://postgres:postgres@127.0.0.1/postgres' + +[group('testing')] +test-pg: + uv run python -m pytest -v --database-location={{DATABASE_URI}}