Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Jens Plüddemann committed Oct 10, 2024
0 parents commit 46af19f
Show file tree
Hide file tree
Showing 168 changed files with 6,229 additions and 0 deletions.
56 changes: 56 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
FROM maven:3-eclipse-temurin-21 AS dind

ARG DEBIAN_FRONTEND=noninteractive
ENV PIP_ROOT_USER_ACTION=ignore

RUN set -eux && \
apt-get update && \
apt-get install -y --no-install-recommends \
sudo \
ca-certificates \
iptables \
net-tools \
openssl \
pigz \
xz-utils \
procps \
supervisor

COPY --from=docker:27-dind /usr/local/bin /usr/local/bin
COPY --from=docker:27-dind /usr/local/libexec/docker/cli-plugins /usr/local/libexec/docker/cli-plugins

COPY entrypoint.sh /usr/local/bin
RUN chmod +x /usr/local/bin/entrypoint.sh

RUN update-alternatives --set iptables /usr/sbin/iptables-legacy
RUN update-alternatives --set ip6tables /usr/sbin/ip6tables-legacy

VOLUME /var/lib/docker

RUN apt-get update && \
apt-get install --yes --no-install-recommends \
sudo \
bash \
curl \
build-essential \
python3.12 \
python-is-python3 \
python3-dev \
python3-pip \
python3-setuptools \
python3-wheel \
python3-psutil && \
apt clean && \
rm -rf /var/lib/apt/lists/*

RUN rm -rf /usr/lib/python3*/EXTERNALLY-MANAGED

COPY requirements.txt /usr/local/src/requirements.txt

RUN pip install -r /usr/local/src/requirements.txt

WORKDIR /workspace

EXPOSE 5000

ENTRYPOINT [ "entrypoint.sh" ]
91 changes: 91 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
{
"name": "otel-getting-started",
"workspaceFolder": "/workspaces/LFS148-code/exercises",
"image": "ghcr.io/lftraining/lfs148-code-application:latest",
"overrideCommand": false,
"runArgs": [
"--privileged"
],
"forwardPorts": [
5000,
5001,
5432,
8080,
8090,
9090,
16686
],
"containerEnv": {
"SHELL": "/bin/bash",
"EXERCISES": "/workspaces/opentelemetry-training/exercises"
},
"portsAttributes": {
"5000": {
"label": "Python Flask app"
},
"5001": {
"label": "Python Flask app"
},
"8080": {
"label": "Spring Boot Backend app"
},
"8090": {
"label": "Spring Boot Thymeleaf app"
},
"9090": {
"label": "Prometheus UI"
},
"16686": {
"label": "Jaeger UI"
},
"5432": {
"label": "Postgres DB"
}
},
"customizations": {
"vscode": {
"settings": {
"files.autoSave": "afterDelay",
"[python]": {
"editor.formatOnSave": true
},
"[dockercompose][yaml]": {
"editor.defaultFormatter": "redhat.vscode-yaml",
"editor.formatOnPaste": true,
"editor.formatOnSave": true,
"editor.insertSpaces": true,
"editor.tabSize": 2
},
"[adoc][markdown]": {
"editor.defaultFormatter": "vscode.markdown-language-features",
"editor.formatOnPaste": true,
"editor.formatOnSave": true,
"editor.insertSpaces": true,
"editor.tabSize": 2
},
"[dockerfile]": {
"editor.quickSuggestions": {
"strings": true
},
"editor.defaultFormatter": "ms-azuretools.vscode-docker"
},
"python.analysis.typeCheckingMode": "strict",
"python.analysis.autoImportCompletions": true
},
"extensions": [
"vscjava.vscode-java-pack",
"vscjava.vscode-java-dependency",
"ms-python.vscode-pylance",
"charliermarsh.ruff",
"ms-python.isort",
"ms-python.python",
"njpwerner.autodocstring",
"KevinRose.vsc-python-indent",
"ms-python.black-formatter",
"usernamehw.errorlens",
"redhat.vscode-yaml",
"ms-azuretools.vscode-docker"
]
}
}
}
7 changes: 7 additions & 0 deletions .devcontainer/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

# Execute specified command
"$@"

/usr/bin/supervisord -n >> /dev/null 2>&1 &
nohup dockerd >/dev/null 2>&1
23 changes: 23 additions & 0 deletions .devcontainer/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Faker==28.4.1
Flask==3.0.3
opentelemetry-api==1.26.0
opentelemetry-distro==0.47b0
opentelemetry-exporter-otlp==1.26.0
opentelemetry-exporter-otlp-proto-http==1.26.0
opentelemetry-exporter-otlp-proto-grpc==1.26.0
opentelemetry-exporter-prometheus==0.47b0
opentelemetry-instrumentation-asyncio==0.47b0
opentelemetry-instrumentation-dbapi==0.47b0
opentelemetry-instrumentation-flask==0.47b0
opentelemetry-instrumentation-grpc==0.47b0
opentelemetry-instrumentation-jinja2==0.47b0
opentelemetry-instrumentation-logging==0.47b0
opentelemetry-instrumentation-sqlite3==0.47b0
opentelemetry-instrumentation-threading==0.47b0
opentelemetry-instrumentation-requests==0.47b0
opentelemetry-instrumentation-system-metrics==0.47b0
opentelemetry-instrumentation-urllib==0.47b0
opentelemetry-instrumentation-wsgi==0.47b0
opentelemetry-sdk==1.26.0
opentelemetry-semantic-conventions==0.47b0
requests==2.32.3
141 changes: 141 additions & 0 deletions .github/workflows/docker-build-and-push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
name: Create and publish a Docker image

on:
push:
branches: ["**"] # run for any commit or tag push on any branch
tags-ignore: ["v**"] # reserve v* tags for releases

env:
REGISTRY_IMAGE: ghcr.io/lftraining/lfs148-code

jobs:
build:
name: Build and publish docker image for ${{ matrix.image }} on ${{ matrix.platform }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
image:
- application
platform:
- linux/amd64
- linux/arm64
include:
- image: application
dockerfile: .devcontainer/Dockerfile
context: .devcontainer/
- platform: linux/arm64
os: [ubuntu-latest]
- platform: linux/amd64
os: [ubuntu-latest]
permissions:
contents: read
packages: write

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Prepare for ${{ matrix.image }} on ${{ matrix.platform }}
run: |
platform=${{ matrix.platform }}
echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
- name: Extract metadata (tags, labels) for Docker from ${{ matrix.image }}
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY_IMAGE }}-${{ matrix.image }}
tags: |
type=ref,event=branch
type=ref,event=tag
type=ref,event=pr
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'main') }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v3

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

- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push by digest for ${{ matrix.image }}
id: build
uses: docker/build-push-action@v6
with:
context: ${{ matrix.context }}
file: ${{ matrix.dockerfile }}
platforms: ${{ matrix.platform }}
labels: ${{ steps.meta.outputs.labels }}
outputs: type=image,name=${{ env.REGISTRY_IMAGE }}-${{ matrix.image }},push-by-digest=true,name-canonical=true,push=true
cache-from: type=gha,scope=build-${{ env.PLATFORM_PAIR }}
cache-to: type=gha,scope=build-${{ env.PLATFORM_PAIR }}

- name: Export digest for ${{ matrix.image }} on ${{ matrix.platform }}
run: |
mkdir -p /tmp/digests
digest="${{ steps.build.outputs.digest }}"
touch "/tmp/digests/${digest#sha256:}"
- name: Upload digest
uses: actions/upload-artifact@v4
with:
name: digests-${{ matrix.image }}-${{ env.PLATFORM_PAIR }}
path: /tmp/digests/*
if-no-files-found: error
retention-days: 1

merge:
runs-on: ubuntu-latest
needs:
- build
strategy:
fail-fast: false
matrix:
image:
- application
steps:
- name: Download digests
uses: actions/download-artifact@v4
with:
path: /tmp/digests
pattern: digests-${{ matrix.image }}*
merge-multiple: true

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

- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY_IMAGE }}-${{ matrix.image }}
tags: |
type=ref,event=branch
type=ref,event=tag
type=ref,event=pr
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'main') }}
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Create manifest list and push
working-directory: /tmp/digests
run: |
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
$(printf '${{ env.REGISTRY_IMAGE }}-${{ matrix.image }}@sha256:%s ' *)
- name: Inspect image
run: |
docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}-${{ matrix.image }}:${{ steps.meta.outputs.version }}
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
**/__pycache__
**/.DS_STORE

*.jar

settings.json
9 changes: 9 additions & 0 deletions .gitpod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Image of workspace. Learn more: https://www.gitpod.io/docs/configure/workspaces/workspace-image
image: maeddes/gitpod:full
workspaceLocation: "/workspace/opentelemetry-training/exercises"

tasks:
- name: Set environment variable
command: eval $(gp env -e EXERCISES=/workspace/opentelemetry-training/exercises)
- name: Add Python Otel libs
command: pip3 install requests flask Faker opentelemetry-api opentelemetry-sdk opentelemetry-exporter-prometheus opentelemetry-exporter-otlp
Loading

0 comments on commit 46af19f

Please sign in to comment.