Skip to content

Commit

Permalink
Updated tests to support new action
Browse files Browse the repository at this point in the history
  • Loading branch information
Arv1nt3 committed Jan 12, 2024
1 parent 4c7c3a3 commit 5a506b7
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 23 deletions.
89 changes: 67 additions & 22 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,88 @@ name: Test

on: [push]

env:
IMAGE_NAME: "nginx"
IMAGE_TAG: "latest"
REGISTRY_URL: "ghcr.io"
REGISTRY_USERNAME: "${{ github.actor }}"
REGISTRY_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
APP_PORT: "80"
PATH: "/"
INITIAL_DELAY_SECONDS: "5"
PERIOD_SECONDS: "10"

jobs:
linter:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v2
uses: actions/checkout@v4.1.1

- name: Lint YAML files
uses: ibiqlik/[email protected]
with:
config_file: .yamllint.yml
tester:

test-remote-image:
needs: linter
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/[email protected]

- name: Set up Docker Buildx
uses: docker/[email protected]

- name: Build image and push to registry
run: |
docker buildx build \
--file ./test/Dockerfile \
--tag ghcr.io/arv1nt3/application:latest \
--push \
./test
- name: Test Action with Sample Nginx Application
uses: Arv1nt3/kubernetes-deployment-tester-action@main
with:
image_name: 'ghcr.io/arv1nt3/application:latest'
use_local_image: false
port: '5000'
registry_token: ${{ secrets.GITHUB_TOKEN }}
registry_url: ghcr.io
registry_username: arv1nt3
command: 'flask'
args: 'run,--host=0.0.0.0'
env_vars: |
- name: APP_KEY
value: "YourAppKeyHere"
- name: Remove Image from ghcr.io
if: success()
run: |
echo ${{ secrets.GITHUB_TOKEN }} | docker login ghcr.io -u ${{ github.actor }} --password-stdin
docker rmi ghcr.io/arv1nt3/application:latest
curl -X DELETE -u ${{ github.actor }}:${{ secrets.GITHUB_TOKEN }} \
"https://ghcr.io/v2/arv1nt3/application/manifests/latest"
test-local-image:
needs: linter
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v2
uses: actions/[email protected]

- name: Set up Docker Buildx
uses: docker/[email protected]

- name: Build image and load locally
run: |
docker buildx build \
--file ./test/Dockerfile \
--tag ghcr.io/arv1nt3/application:latest \
--load \
./test
- name: Test Action with Sample Nginx Application
uses: Arv1nt3/kubernetes-deployment-tester-action@main
with:
image_name: '${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }}'
registry_url: ${{ env.REGISTRY_URL }}
registry_username: ${{ env.REGISTRY_USERNAME }}
registry_token: ${{ env.REGISTRY_TOKEN }}
port: ${{ env.APP_PORT }}
path: ${{ env.PATH }}
initialDelaySeconds: ${{ env.INITIAL_DELAY_SECONDS }}
periodSeconds: ${{ env.PERIOD_SECONDS }}
image_name: 'ghcr.io/arv1nt3/application:latest'
use_local_image: true
port: '5000'
registry_token: ${{ secrets.GITHUB_TOKEN }}
registry_url: ghcr.io
registry_username: arv1nt3
command: 'flask'
args: 'run,--host=0.0.0.0'
env_vars: |
- name: APP_KEY
value: "YourAppKeyHere"
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ inputs:
periodSeconds:
description: "How often (in seconds) to perform the probe. Minimum value is 1."
required: false
default: "10"
default: "5"

runs:
using: "composite"
Expand Down
18 changes: 18 additions & 0 deletions test/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Use a lightweight Python base image
FROM python:3.9-slim

# Install Flask
RUN pip install Flask

# Set the working directory
WORKDIR /app

# Copy the application script
COPY app.py /app/app.py

# The container listens on port 5000 by default
EXPOSE 5000

# The application requires an environment variable APP_KEY to run
# The application is started with 'flask run' command, which can be set through CMD
CMD ["flask", "run", "--host=0.0.0.0"]
14 changes: 14 additions & 0 deletions test/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from flask import Flask
import os

app = Flask(__name__)

@app.route('/')
def hello():
app_key = os.environ.get('APP_KEY')
if not app_key:
return "APP_KEY not set!", 500
return f"Hello, World! APP_KEY is {app_key}", 200

if __name__ == "__main__":
app.run()

0 comments on commit 5a506b7

Please sign in to comment.