Skip to content

Commit

Permalink
Merge pull request #2 from sendblocks/changes-from-the-original-repo
Browse files Browse the repository at this point in the history
Changes from the original repo
  • Loading branch information
dor-sendblocks committed Apr 16, 2024
2 parents ec358c9 + 6be5c34 commit 10ff0f4
Show file tree
Hide file tree
Showing 42 changed files with 714 additions and 105 deletions.
24 changes: 24 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
name: Bug report
about: Create a report to help us improve
title: ''
labels: bug
assignees: ''

---

**Describe the bug**
A clear and concise description of what the bug is.

**To Reproduce**
Steps to reproduce the behavior:
1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See error

**Expected behavior**
A clear and concise description of what you expected to happen.

**Actual behavior**
A clear and concise description of what actually happens.
20 changes: 20 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
name: Feature request
about: Suggest an idea for this project
title: ''
labels: enhancement
assignees: ''

---

**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

**Describe the solution you'd like**
A clear and concise description of what you want to happen.

**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.

**Additional context**
Add any other context or screenshots about the feature request here.
59 changes: 45 additions & 14 deletions .github/scripts/create_version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,52 @@ cd "${SCRIPT_DIR}/../../application"
name=$(cat Chart.yaml | yq '.name')
version=$(cat Chart.yaml | yq '.version')

# Define the internal variable (set it to true if it's sendblocks changes and not official changes by the author)
# Prompt user to specify if the version is internal
echo "Is the version internal? (yes/no)"
read answer
internal=false
if [ "${answer}" == "yes" ]; then
internal=true
fi

# Backup the original Chart.yaml
cp Chart.yaml Chart.yaml.backup

# Check if internal is true and append "_sb" to the version if it is
# The version in Chart.yaml remains unchanged
new_version=${version}

if $internal; then
new_version="${version}-sb"
yq eval -i ".version = \"$new_version\"" Chart.yaml
# Fetch all versions from ECR starting with the specified version prefix and ending with -sb.x
# Note: Adjust the following command to match your AWS CLI version and query capabilities
versions=$(aws --profile shared ecr-public describe-images --region us-east-1 --repository-name ${name} --query 'sort_by(imageDetails,& imagePushedAt)[*].imageTags' --output text | grep "^${version}-sb" | sort -V)
if [ -z "${versions}" ]; then
# If no versions found, start with -sb.1
ecr_version="${version}-sb.1"
else
# If versions found, pick the last one and increment
last_version=$(echo "${versions}" | tail -n 1)
num=$(echo "$last_version" | grep -o -E '[0-9]+$')
new_num=$((num + 1))
ecr_version="${version}-sb.${new_num}"
fi
# For internal use, we will use ecr_version to tag the ECR image
yq eval -i ".version = \"${ecr_version}\"" Chart.yaml
else
new_version=$version
# For non-internal use, we keep the ECR tag same as the Chart version
ecr_version=$version
fi

# Proceed with packaging using the original version in Chart.yaml
output=$(helm package .)
app_name=$(echo "$output" | awk '{print $NF}')
chart_tgz_path=$(echo "$output" | awk '{print $NF}')

# Restore the original Chart.yaml from the backup
mv Chart.yaml.backup Chart.yaml

# Temporarily disable exit on error
# Temporarily disable exit on error for AWS CLI operations
set +e

create_output=$(aws --profile shared ecr-public create-repository --repository-name ${name} --region us-east-1 2>&1)
create_output=$(aws --profile shared ecr-public create-repository --region us-east-1 --repository-name ${name} 2>&1)
create_status=$?

# Re-enable exit on error
Expand All @@ -47,21 +69,30 @@ else
exit 1
fi

registry_uri=$(aws --profile shared ecr-public describe-registries --region us-east-1 --query "registries[0].registryUri" --output text)

# Temporarily disable exit on error
# Temporarily disable exit on error for AWS CLI operations
set +e

image_exists=$(aws --profile shared ecr-public describe-images --repository-name ${name} --image-ids imageTag=${new_version} --region us-east-1 2>&1)
registry_uri=$(aws --profile shared ecr-public describe-registries --region us-east-1 --query "registries[0].registryUri" --output text)
# Check if the image version (for internal use, the ecr_version) already exists in the repository
image_exists=$(aws --profile shared ecr-public describe-images --region us-east-1 --repository-name ${name} --image-ids imageTag=${ecr_version} 2>&1)
image_exists_status=$?

# Re-enable exit on error
set -e

if [[ $image_exists_status -eq 0 ]]; then
echo "Error: The version ${new_version} already exists in the repository."
echo "Error: The version ${ecr_version} already exists in the repository."
rm ${chart_tgz_path}
exit 1
fi

# Login to ECR and push the image
aws --profile shared ecr-public get-login-password --region us-east-1 | helm registry login --username AWS --password-stdin public.ecr.aws
helm push ${app_name} oci://${registry_uri}
echo "chart tgz path: ${chart_tgz_path}"
echo "registry: oci://${registry_uri}"
echo "version: ${ecr_version}"
helm push ${chart_tgz_path} oci://${registry_uri}

rm ${chart_tgz_path}

echo "Completed successfully"
98 changes: 98 additions & 0 deletions .github/workflows/pull_request.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
name: Pull Request

on:
pull_request_target:
branches:
- master

env:
CHART_NAME: "application"

jobs:
build:
name: Build
if: "! contains(toJSON(github.event.commits.*.message), '[skip-ci]')"
runs-on: stakater-nonprod

steps:

- name: Check out code
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{github.event.pull_request.head.sha}}

# Set Up Helm
- name: Set up Helm
uses: azure/setup-helm@v4
with:
version: v3.8.2

# Lint
- name: Helm Lint
run: |
helm lint ${CHART_NAME}
helm lint ${CHART_NAME} -f ${CHART_NAME}/values-test.yaml
- name: Run Checkov action
uses: bridgecrewio/checkov-action@master
with:
quiet: true
file: ${CHART_NAME}/Chart.yaml
var_file: ${CHART_NAME}/values-test.yaml

- name: Install kubectl
uses: azure/setup-kubectl@v3
with:
version: v1.26.0

- name: Install CLI tools from OpenShift Mirror
uses: redhat-actions/openshift-tools-installer@v1
with:
oc: "4"

# This is used to setup kubeconfig, required by Tilt
- name: Login to cluster
run: oc login --token=$(cat /var/run/secrets/kubernetes.io/serviceaccount/token) --server=https://kubernetes.default.svc --insecure-skip-tls-verify=true

# This is required for adding ghcr helm registry
- name: Login to Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io/stakater
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

# Dry run to ensure that manifests are generated successfully
- name: Dry Run Chart
run: |
helm install ${CHART_NAME} ${CHART_NAME} -f ${CHART_NAME}/values-test.yaml -n stakater-chart-pipeline-test --dry-run --debug
- name: Comment on PR
uses: mshick/add-pr-comment@v2
env:
GITHUB_TOKEN: ${{ secrets.STAKATER_GITHUB_TOKEN }}
with:
message-success: '@${{ github.actor }} validation successful`'
message-failure: '@${{ github.actor }} Yikes! You better fix it before anyone else finds out! [Build](https://github.com/${{ github.repository }}/commit/${{ github.event.pull_request.head.sha }}/checks) has Failed!'
allow-repeats: false

- name: Notify Slack
uses: 8398a7/action-slack@v3
if: always() # Pick up events even if the job fails or is canceled.
with:
status: ${{ job.status }}
fields: repo,author,action,eventName,ref,workflow
env:
SLACK_WEBHOOK_URL: ${{ secrets.STAKATER_DELIVERY_SLACK_WEBHOOK }}

unittest:
name: Unit Tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{github.event.pull_request.head.sha}}
- uses: d3adb5/helm-unittest-action@v2
with:
charts: application
Loading

0 comments on commit 10ff0f4

Please sign in to comment.