Skip to content

Commit

Permalink
created poetry version, tags and image versions for dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
Ncoder2 committed Jun 16, 2024
1 parent eab2975 commit 619c0d1
Show file tree
Hide file tree
Showing 7 changed files with 1,547 additions and 20 deletions.
35 changes: 35 additions & 0 deletions .github/actions/bump-version-and-git-tag/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Bump Poetry Version
description: Bumps the poetry version based on the release type and creates a new git tag.
inputs:
releaseType:
description: 'The type of release'
required: true

runs:
using: "composite"
steps:
- name: Bump poetry version
shell: bash
run: |
# Create Latest Image Version
poetry version "${{ inputs.releaseType }}"
latest_image_version=$(poetry version --short)
echo "LATEST_IMAGE_VERSION=$latest_image_version" >> $GITHUB_ENV
# Create git Tag version for dashboard
tag_version="dashboard-${latest_image_version}"
echo "TAG_VERSION=$tag_version" >> $GITHUB_ENV
# Add commit messsage for message bump
git add .
git commit -m "Bump poetry version to $latest_image_version"
# Check if the new version tag already exists
if git rev-parse "$tag_version" >/dev/null 2>&1; then
echo "Tag $tag_version already exists."
else
# Commit and tag the new version
echo "Tag $tag_version does not exist."
git tag -a $tag_version -m "$tag_version"
git show "$tag_version"
fi
23 changes: 23 additions & 0 deletions .github/actions/setup-python-and-git/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: checkout-and-setup-python
description: 'Checkout the repository and setup Python'
inputs:
python-version:
description: 'Python version to use'
required: false
default: '3.11'
runs:
using: 'composite'
steps:
- uses: actions/setup-python@v4
name: Setup Python
with:
python-version: ${{ inputs.python-version }}
cache: 'pip' # caching pip dependencies

- name: Git check
run: |
git config --global user.email "[email protected]"
git config --global user.name "mantis"
git --version
git config --list
shell: bash
54 changes: 54 additions & 0 deletions .github/workflows/mantis-dashboard-pr-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: Dashboard PR Release
on:
pull_request:
branches:
- dashboard
types:
- closed
workflow_dispatch:

env:
REGISTRY: ghcr.io
IMAGE_NAME: ncoder2/mantis-dashboard-upstream
jobs:
build-and-push-image:
if: github.event_name == 'pull_request' && github.event.action == 'closed' && github.event.pull_request.merged == true
runs-on: ubuntu-latest
permissions:
contents: write
packages: write
actions: write

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

- name: Setup Python and Git
uses: ./.github/actions/setup-python-and-git
with:
python-version: '3.9'

- name: Install Poetry
run: pip install poetry==1.4.2

- name: Log in to the Container registry
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}


- name: Build and push Docker image
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4
with:
context: .
push: true
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
labels: ${{ steps.meta.outputs.labels }}
61 changes: 47 additions & 14 deletions .github/workflows/mantis-dashboard-release.yml
Original file line number Diff line number Diff line change
@@ -1,41 +1,74 @@
name: Mantis Dashboard Release
name: Dashboard Latest Release
on:
push:
branches:
- dashboard
workflow_dispatch:
inputs:
releaseType:
description: 'What kind of release is this?'
required: true
type: choice
options:
- 'major'
- 'minor'
- 'patch'

env:
REGISTRY: ghcr.io
IMAGE_NAME: phonepe/mantis-dashboard

jobs:
build-and-push-image:
if: github.event_name == 'workflow_dispatch' && github.ref == 'refs/heads/dashboard'
runs-on: ubuntu-latest
permissions:
contents: read
contents: write
packages: write

actions: write

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

with:
fetch-depth: 0 # added to fetch tags from git

- name: Setup Python and Git
uses: ./.github/actions/setup-python-and-git
with:
python-version: '3.9'

- name: Install Poetry
run: pip install poetry==1.4.2

- name: Bump poetry version and add git tag
uses: ./.github/actions/bump-version-and-git-tag
with:
releaseType: ${{ inputs.releaseType }}

- name: Push tag changes
run: |
git push -u origin main
git push origin ${{ env.TAG_VERSION }}
git log -1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Log in to the Container registry
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

- name: Build and push Docker image
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4
with:
context: .
push: true
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
labels: ${{ steps.meta.outputs.labels }}
tags: |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.LATEST_IMAGE_VERSION }}
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
labels: ${{ steps.meta.outputs.labels }}
26 changes: 20 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,28 @@ RUN apt-get update -y && apt-get upgrade -y

# Setup work directory
WORKDIR /home/
RUN python -m pip install --upgrade pip
RUN pip install --upgrade setuptools
RUN python -m pip install --upgrade setuptools wheel

# Copy requirements.txt for mantis
COPY ./requirements.txt /home/requirements.txt
# Install Poetry
RUN pip install poetry==1.4.2

RUN pip install --upgrade setuptools
RUN pip install -r requirements.txt
# Add Poetry to PATH
ENV PATH="/root/.local/bin:$PATH"

# Setup Poetry ENV variables
ENV POETRY_NO_INTERACTION=1 \
POETRY_VIRTUALENVS_IN_PROJECT=0 \
POETRY_VIRTUALENVS_CREATE=0 \
POETRY_CACHE_DIR=/tmp/poetry_cache

# Copy pyproject.toml and poetry.lock
COPY pyproject.toml poetry.lock* /home/

# Install dependencies using Poetry
RUN poetry install --without dev --no-root && rm -rf $POETRY_CACHE_DIR
COPY . .
EXPOSE 8000

CMD uvicorn main:app --host 0.0.0.0 --port 8000

CMD uvicorn main:app --host 0.0.0.0 --port 8000
Loading

0 comments on commit 619c0d1

Please sign in to comment.