Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: cleanup setup #19

Merged
merged 7 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 13 additions & 82 deletions .github/workflows/containers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,94 +3,25 @@ name: Containers - distributed-calendar
on:
push:
branches: [ 'main' ]
paths: [ 'dapr-distributed-calendar/**' ]
paths: [ 'go/**', 'node/**', 'python/**' ]
pull_request:
branches: [ 'main' ]
paths: [ 'dapr-distributed-calendar/**' ]
paths: [ 'go/**', 'node/**', 'python/**' ]

env:
platforms: linux/amd64

QUAY_USER: "${{ fromJSON(secrets.VAULT_KV_1D187965_OP_QUAY_ROBOT_ACCOUNT).username }}"
QUAY_TOKEN: "${{ fromJSON(secrets.VAULT_KV_1D187965_OP_QUAY_ROBOT_ACCOUNT).password }}"
BOT_ACCESS_TOKEN: "${{ fromJSON(secrets.VAULT_KV_1D187965_OP_GITHUB_INFRALOVERS).PAT }}"

jobs:
build:
strategy:
fail-fast: false
matrix:
container: [ go, node, python ]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Prepare tagging
id: prep
run: |
IMAGE_NAME=$(basename ${{ github.repository }})
IMAGE_REPO=${{ github.repository_owner }}
if [[ -n "${{ secrets.IMAGE_NAME }}" ]]; then
IMAGE_NAME="${{ secrets.IMAGE_NAME }}"
fi
if [[ -n "${{ secrets.IMAGE_REPO }}" ]]; then
IMAGE_REPO="${{ secrets.IMAGE_REPO }}"
fi
QUAY_IMAGE="quay.io/${IMAGE_REPO}/${IMAGE_NAME}:${{ matrix.container }}"
GHCR_IMAGE="ghcr.io/${{ github.repository }}-${{ matrix.container }}"
VERSION="dev"
if [[ '${{ needs.prebuild.outputs.version }}' != '' ]]; then
VERSION="${{ needs.prebuild.outputs.version }}"
fi
if [ "${{ github.event_name }}" = "schedule" ]; then
VERSION="nightly"
fi
TAGS="${QUAY_IMAGE},${GHCR_IMAGE}:${VERSION}"
if [[ $VERSION =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
TAGS="$TAGS,${GHCR_IMAGE}:latest"
fi
echo "settings tag ${TAGS}"
echo "tags=${TAGS}" >> $GITHUB_OUTPUT

- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v3

- name: Set up QEMU
uses: docker/setup-qemu-action@v3
with:
platforms: ${{ env.platforms }}

- name: Cache Docker layers
uses: actions/cache@v2
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}-${{ matrix.container }}
restore-keys: |
${{ runner.os }}-buildx-

- name: Login to Quay
if: ${{ github.ref_name == github.event.repository.default_branch }}
uses: docker/login-action@v3
with:
registry: quay.io
username: ${{ env.QUAY_USER }}
password: ${{ env.QUAY_TOKEN }}

- name: Login to GitHub Container Registry
if: ${{ github.ref_name == github.event.repository.default_branch }}
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ env.BOT_ACCESS_TOKEN }}

- name: Build and push
id: docker_build
uses: docker/build-push-action@v5
with:
builder: ${{ steps.buildx.outputs.name }}
context: ./dapr-distributed-calendar/${{ matrix.container }}/
push: ${{ github.ref_name == github.event.repository.default_branch }}
tags: ${{ steps.prep.outputs.tags }}
platforms: ${{ env.platforms }}
uses: infralovers/.github/.github/workflows/container.yml@main
secrets:
QUAY_USER: "${{ fromJSON(secrets.VAULT_KV_1D187965_OP_QUAY_ROBOT_ACCOUNT).username }}"
QUAY_TOKEN: "${{ fromJSON(secrets.VAULT_KV_1D187965_OP_QUAY_ROBOT_ACCOUNT).password }}"
BOT_ACCESS_TOKEN: "${{ fromJSON(secrets.VAULT_KV_1D187965_OP_GITHUB_INFRALOVERS).PAT }}"
# MONDOO_SERVICE_ACCOUNT: "${{ fromJson(secrets.VAULT_KV_1D187965_OP_MONDOO_PACKER_AGENT).password }}"
with:
dockerfile: "${{ matrix.container }}/Dockerfile"
score: 50
platforms: "linux/amd64, linux/arm64"
release: false
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go/go_events
node/node_modules
50 changes: 8 additions & 42 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
```shell
# dapr-distributed-calendar
https://github.com/dapr/samples

# distributed-calculator
https://github.com/dapr/quickstarts
```

## dapr-distributed-calendar
Expand All @@ -33,17 +30,22 @@ DELETE: <http://localhost:3000/event/1>

GET: <http://localhost:3000/event/1>

### Local Setup

```shell
./local-setup.sh

```

### Setup with docker-compose

```shell
cd 12-factor-app/dapr-distributed-calendar
docker-compose up
```

### Setup with Kubernetes

```shell
cd 12-factor-app/dapr-distributed-calendar
./kubernetes-deploy.sh
```

Expand All @@ -58,40 +60,4 @@ Every part of the deployment process that is not required, has a `OPTIONAL` comm

### About Auto-Instrumentation

It is theoretically possible to use auto-instrumentation for kubernetes, but sadly this is very buggy especially Go and Python. and even those that do work do not provide a very good instrumentation when it comes to metrics, traces and logs. Therefore thy have been uncommented in the code, but can still be found within the folder `12-factor-app/dapr-distributed-calendar/otel`.

## distributed-calculator

The distributed-calculator works, and I added DELETE and PUT to the already existing POST and GET requests:

```bash
curl -s http://localhost:8000/calculate/add -H Content-Type:application/json --data @operands.json
```

```bash
curl -s http://localhost:8000/calculate/subtract -H Content-Type:application/json --data @operands.json
```

```bash
curl -s http://localhost:8000/calculate/divide -H Content-Type:application/json --data @operands.json
```

```bash
curl -s http://localhost:8000/calculate/multiply -H Content-Type:application/json --data @operands.json
```

```bash
curl -s http://localhost:8000/persist -H Content-Type:application/json --data @persist.json
```

```bash
curl -s http://localhost:8000/state
```

```bash
curl -s -X PUT http://localhost:8000/state -H 'Content-Type: application/json' --data-raw '{"next": "12", "operation": "-" }'
```

```bash
curl -s -X DELETE http://localhost:8000/state
```
It is theoretically possible to use auto-instrumentation for kubernetes, but sadly this is very buggy especially Go and Python. and even those that do work do not provide a very good instrumentation when it comes to metrics, traces and logs. Therefore thy have been uncommented in the code, but can still be found within the folder `12-factor-app/otel`.
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
version: '3.8'
services:
############################
# Node app + Dapr sidecar
Expand Down Expand Up @@ -47,7 +46,7 @@ services:
image: "daprio/daprd:edge"
command: ["./daprd",
"-app-id", "messages",
"-app-port", "5000",
"-app-port", "5000",
"-dapr-http-port", "3501",
"-placement-host-address", "placement:50006",
"-components-path", "/components"]
Expand Down Expand Up @@ -111,7 +110,7 @@ services:
# traefik api gateway
############################
traefik:
image: traefik:v2.9
image: traefik:v3.2
command:
- "--api.insecure=true" # Don't do that in production!
- "--providers.docker=true"
Expand Down
File renamed without changes.
Loading
Loading