Skip to content

Commit

Permalink
Trying the manifest piece
Browse files Browse the repository at this point in the history
  • Loading branch information
Mathew Walters authored and Mathew Walters committed Nov 6, 2024
1 parent 07524be commit 45ead15
Showing 1 changed file with 45 additions and 14 deletions.
59 changes: 45 additions & 14 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
name: CI/CD
name: Build, Publish, and Update Manifests

on:
push:
branches:
- main
pull_request:
branches:
- main

permissions:
contents: read
packages: write # Grant write permissions for packages
env:
APP_NAME: "my-app" # Replace with your app name or pass it as an input
ENVIRONMENT: "production" # Set different values for different environments if needed
REGISTRY: "ghcr.io/${{ github.repository_owner }}" # Update with your registry path
IMAGE_TAG: ${{ github.sha }} # Use the commit SHA as the image tag for versioning

jobs:
build-and-push:
build-publish-and-setup:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2
Expand All @@ -32,12 +31,44 @@ jobs:

- name: Build Docker image
run: |
docker build -t ghcr.io/$REPO_OWNER/demo-app:${{ github.sha }} .
docker build -t ghcr.io/$REPO_OWNER/$APP_NAME:${{ env.IMAGE_TAG }} .
- name: Push Docker image
run: |
docker push ghcr.io/$REPO_OWNER/demo-app:${{ github.sha }}
docker push ghcr.io/$REPO_OWNER/$APP_NAME:${{ env.IMAGE_TAG }}
- name: Set up new app manifests
run: |
# Define paths and new app folder
TEMPLATE_DIR="kubernetes/_templates/app"
NEW_APP_DIR="kubernetes/$APP_NAME"
# Copy the template directory to the new app folder
mkdir -p $NEW_APP_DIR
cp $TEMPLATE_DIR/* $NEW_APP_DIR
# Replace placeholders in deployment.yaml
sed -i "s|{{APP_NAME}}|$APP_NAME|g" $NEW_APP_DIR/deployment.yaml
sed -i "s|{{ENVIRONMENT}}|$ENVIRONMENT|g" $NEW_APP_DIR/deployment.yaml
sed -i "s|{{REGISTRY}}|$REGISTRY|g" $NEW_APP_DIR/deployment.yaml
sed -i "s|{{IMAGE_TAG}}|${{ env.IMAGE_TAG }}|g" $NEW_APP_DIR/deployment.yaml
# Replace placeholders in service.yaml
sed -i "s|{{APP_NAME}}|$APP_NAME|g" $NEW_APP_DIR/service.yaml
sed -i "s|{{ENVIRONMENT}}|$ENVIRONMENT|g" $NEW_APP_DIR/service.yaml
# (Optional) Log the changes for verification
echo "Generated manifests for $APP_NAME:"
cat $NEW_APP_DIR/deployment.yaml
cat $NEW_APP_DIR/service.yaml
cat $NEW_APP_DIR/kustomization.yaml
- name: Output image tag
- name: Commit and Push Changes
run: |
echo "Image: ghcr.io/$REPO_OWNER/demo-app:${{ github.sha }}"
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git add kubernetes/$APP_NAME
git commit -m "Add manifests for $APP_NAME based on template"
git push
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 comments on commit 45ead15

Please sign in to comment.