-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
93f0aca
commit 6a6e668
Showing
4 changed files
with
181 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
# Copyright 2010 New Relic, Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
--- | ||
name: Test Python init container image | ||
|
||
on: | ||
# Allow manual trigger. | ||
workflow_dispatch: | ||
push: | ||
# Run tests on push to main or PR. | ||
branches: | ||
- main | ||
pull_request: | ||
# Do not run when a tag is created. | ||
tags-ignore: | ||
- "**" | ||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
- name: Build | ||
run: go build -o myapp . | ||
- name: Docker Build and Push | ||
uses: docker/build-push-action@v2 | ||
with: | ||
context: . | ||
push: true | ||
tags: your-docker-registry/your-repo:latest | ||
concurrency: | ||
group: ${{ github.ref || github.run_id }} | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout code | ||
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # 4.1.1 | ||
with: | ||
persist-credentials: false | ||
fetch-depth: 0 | ||
|
||
- name: Set up Docker Buildx | ||
id: buildx | ||
uses: docker/setup-buildx-action@d70bba72b1f3fd22344832f00baa16ece964efeb # 3.3.0 | ||
|
||
- name: Generate Docker metadata (tags and labels) | ||
id: meta | ||
uses: docker/metadata-action@8e5442c4ef9f78752691e2d8f8d19755c6f78e81 # 5.5.1 | ||
with: | ||
images: ghcr.io/${{ github.repository }}-python | ||
flavor: | | ||
prefix= | ||
suffix= | ||
latest=false | ||
tags: | | ||
type=raw,value=latest,enable={{is_default_branch}} | ||
type=schedule,pattern={{date 'YYYY-MM-DD'}} | ||
type=sha,format=short,prefix=sha- | ||
type=sha,format=long,prefix=sha- | ||
- name: Login to GitHub Container Registry | ||
if: github.event_name != 'pull_request' | ||
uses: docker/login-action@e92390c5fb421da1463c202d546fed0ec5c39f20 # 3.1.0 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.repository_owner }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Build and publish init container image | ||
uses: docker/build-push-action@2cdde995de11925a030ce8070c3d77a52ffcf1c0 # 5.3.0 | ||
with: | ||
push: ${{ github.event_name != 'pull_request' }} | ||
context: .github/containers | ||
platforms: ${{ (format('refs/heads/{0}', github.event.repository.default_branch) == github.ref) && 'linux/amd64,linux/arm64' || 'linux/amd64' }} | ||
tags: ${{ steps.meta.outputs.tags }} | ||
labels: ${{ steps.meta.outputs.labels }} | ||
|
||
- name: Build and publish test app image | ||
uses: docker/build-push-action@2cdde995de11925a030ce8070c3d77a52ffcf1c0 # 5.3.0 | ||
with: | ||
push: ${{ github.event_name != 'pull_request' }} | ||
context: .github/containers | ||
platforms: ${{ (format('refs/heads/{0}', github.event.repository.default_branch) == github.ref) && 'linux/amd64,linux/arm64' || 'linux/amd64' }} | ||
tags: ${{ steps.meta.outputs.tags }} | ||
labels: ${{ steps.meta.outputs.labels }} | ||
|
||
- name: Start minikube | ||
uses: medyagh/setup-minikube@317d92317e473a10540357f1f4b2878b80ee7b95 # 0.0.16 | ||
|
||
- name: Build image | ||
run: | | ||
export SHELL=/bin/bash | ||
minikube -p minikube docker-env | ||
make build-image | ||
echo -n "verifying images:" | ||
docker images | ||
- name: Deploy to minikube | ||
run: | | ||
kubectl apply -f deploy/deploy-minikube.yaml | ||
# Wait 30 seconds for the cluster to start and then hit an application endpoint. | ||
- name: Test service URLs | ||
run: | | ||
curl $(minikube service --wait 30 discover --url)/version | ||
curl http://localhost:5000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
--- | ||
apiVersion: newrelic.com/v1alpha1 | ||
kind: Instrumentation | ||
metadata: | ||
labels: | ||
app.kubernetes.io/name: instrumentation | ||
app.kubernetes.io/created-by: newrelic-agent-operator | ||
name: newrelic-instrumentation | ||
spec: | ||
python: | ||
image: ghcr.io/${{ github.repository }}-python | ||
env: | ||
# Put the agent in developer mode so it doesn't try to connect to the real collector. | ||
- name: NEW_RELIC_DEV_MODE | ||
value: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import newrelic.agent | ||
from flask import Flask | ||
|
||
app = Flask(__name__) | ||
|
||
@app.route("/") | ||
def hello_world(): | ||
transaction = newrelic.agent.current_transaction() | ||
if not transaction: | ||
flask.abort(417) | ||
return "<p>Hello, World!</p>" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
--- | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: flask-hello-world | ||
spec: | ||
selector: | ||
matchLabels: | ||
app: flask-hello-world | ||
replicas: 1 | ||
template: | ||
metadata: | ||
labels: | ||
app: flask-hello-world | ||
annotations: | ||
instrumentation.newrelic.com/inject-python: "true" | ||
spec: | ||
containers: | ||
- name: flask-hello-world | ||
image: ghcr.io/anuraaga/flask-hello-world:latest | ||
ports: | ||
- containerPort: 5000 | ||
--- | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: flask-hello-world-service | ||
spec: | ||
type: ClusterIP | ||
ports: | ||
- port: 80 | ||
targetPort: 5000 | ||
selector: | ||
app: flask-hello-world |