Skip to content

Commit

Permalink
Merge pull request #1 from kaizentm/eedorenko/bring-gm-back
Browse files Browse the repository at this point in the history
Eedorenko/bring gm back
  • Loading branch information
eedorenko authored Oct 26, 2023
2 parents 0b65c15 + c724ed8 commit 76ce2ab
Show file tree
Hide file tree
Showing 7 changed files with 305 additions and 101 deletions.
100 changes: 100 additions & 0 deletions .github/workflows/cd.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
name: deploy


on:
workflow_dispatch:
inputs:
commit_id:
required: true
type: string
description: 'Source commit_id (e.g. 62d1d965735a80afca35da9ec8d8aeb39db2da6c)'
environment:
required: false
type: string
description: 'Environment to deploy to (e.g. d2)'
promotion:
required: false
type: string
default: y
description: 'If the change is a subject for the promotion (e.g. Y)'
version:
required: true
type: string
description: 'Version (e.g. 0.0.150-1)'

env:
IMAGE_REPO: ghcr.io/${{ github.repository }}/${{ vars.APP_NAME }}

jobs:
Deploy:
name: "Deploy"
runs-on: ubuntu-latest
environment: ${{ inputs.environment }}
steps:

- name: Checkout
uses: actions/checkout@v3
with:
ref: ${{ inputs.commit_id }}
- name: Checkout Configs
uses: actions/[email protected]
with:
repository: ${{ vars.CONFIGS_REPO }}
ref: ${{ inputs.environment }}
path: configs
token: ${{ secrets.CD_BOOTSTRAP_TOKEN }}

- name: Get Config Commit Id
run: |
CONFIG_COMMIT_ID=$(git rev-parse HEAD)
echo "CONFIG_COMMIT_ID=$CONFIG_COMMIT_ID" >> $GITHUB_ENV
working-directory: configs

- name: Set Image Name, Package Name and Version
run: |
IMAGE_NAME=$IMAGE_REPO:$VERSION
PACKAGE_NAME=$APP_NAME-$VERSION.deb
echo "IMAGE_NAME=$IMAGE_NAME" >> $GITHUB_ENV
echo "VERSION=$VERSION" >> $GITHUB_ENV
env:
VERSION: ${{ inputs.version }}
APP_NAME: ${{ vars.APP_NAME }}


# - name: Generate Manifests
# run: |
# .github/workflows/utils/generate-manifests.sh "$HELM_PATH" "$CONFIGS_PATH" "$MANIFESTS_PATH"
# env:
# HELM_PATH: ${{ github.workspace }}/helm
# CONFIGS_PATH: ${{ github.workspace }}/configs
# MANIFESTS_PATH: ${{ github.workspace }}/manifests
# WORKLOAD: ${{ github.event.repository.name }}
# ENVIRONMENT: ${{ inputs.environment }}
# SOURCE_REPO: ${{ github.event.repository.full_name }}
# SOURCE_BRANCH: ${{ github.event.repository.default_branch }}
# GITOPS_REPO: ${{ vars.MANIFESTS_REPO }}
# VERSION: ${{ env.VERSION }}
# SRC_COMMIT: ${{ inputs.commit_id }}


# - name: Create PR
# run: |
# promoted=$(if [ ${{ inputs.promotion }} == "y" ]; then echo "promoted"; fi)
# .github/workflows/utils/create-pr.sh -s "$MANIFESTS_PATH" -d . -r "$MANIFESTS_REPO" -b "$ACTIVE_ENVIRONMENT" -i "$IMAGE_NAME" -t "$TOKEN" -e "$ACTIVE_ENVIRONMENT" -m N -l $promoted
# env:
# PROMOTED_COMMIT_ID: ${{ inputs.commit_id }}
# CONFIG_COMMIT_ID: ${{ env.CONFIG_COMMIT_ID }} # from the Get Config Commit Id step
# MANIFESTS_PATH: ${{ github.workspace }}/manifests
# MANIFESTS_REPO: https://github.com/${{ vars.MANIFESTS_REPO }}
# TOKEN: ${{ secrets.CD_BOOTSTRAP_TOKEN }}
# ACTIVE_ENVIRONMENT: ${{ inputs.environment }}

# - name: Update Commit Status
# run: |
# .github/workflows/utils/update-status.sh "pending" "Promoted" "$ACTIVE_ENVIRONMENT"
# env:
# GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# PROMOTED_COMMIT_ID: ${{ inputs.commit_id }}
# ACTIVE_ENVIRONMENT: ${{ inputs.environment }}

139 changes: 139 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
name: ci

on:
push:
branches:
- main
- eedorenko/*
workflow_dispatch:

env:
IMAGE_REPO: ghcr.io/${{ github.repository }}/${{ vars.APP_NAME }}
PACKAGE_STORAGE_BASE_URL: https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}

jobs:
CI:
runs-on: ubuntu-latest
permissions: write-all

steps:
- name: Checkout Source
uses: actions/checkout@v3
- name: Login to ghcr
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Generate Image Tag
id: generate_image_tag
run: |
VERSION=${{ vars.SEM_VER }}-${{ github.run_number }}
echo "VERSION=$VERSION" >> $GITHUB_ENV
- name: Build and Push to ghcr
uses: docker/build-push-action@v2
with:
push: true
context: .
tags: ${{ env.IMAGE_REPO }}:${{ env.VERSION }}, ${{ env.IMAGE_REPO }}:latest
- name: Build debian package
id: build_debian_package
run: |
containerID=$(docker run -dt $IMAGE_REPO:$VERSION)
docker cp $containerID:/opt/app/sample .
docker build --platform linux/x86_64 --build-arg version_string=$VERSION --build-arg binary_name=sample --build-arg deb_package_name=hello-world --build-arg deb_package_description="Hello World Application" -t fpm -f Dockerfile-fpm .
containerID=$(docker run --platform linux/x86_64 -dt fpm)
mkdir -p package
package_name=$APP_NAME-$VERSION.deb
docker cp $containerID:/deb-package/$package_name ./package/
env:
APP_NAME: ${{ vars.APP_NAME }}
- name: Publish debian package
uses: JamesIves/github-pages-deploy-action@v4
with:
folder: package
branch: packages
target-folder: .
clean: false
- name: Start CD
run: |
gh workflow run cd.yaml -f commit_id="$PROMOTED_COMMIT_ID" -f version="$VERSION" -r ${{ github.ref_name }}
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PROMOTED_COMMIT_ID: ${{ github.sha }}

# - name: Checkout Configs
# uses: actions/[email protected]
# with:
# ref: dev-configs
# path: configs
# - name: Read Image Tags
# run: |
# IMAGE_TAG=${{ needs.Build_Push_Image.outputs.image_tag }}
# echo "IMAGE_TAG=$IMAGE_TAG" >> $GITHUB_ENV
# VERSION=$IMAGE_TAG
# echo "VERSION=$VERSION" >> $GITHUB_ENV
# - name: Read Package Name
# run: |
# PACKAGE_NAME=${{ needs.Build_Push_Image.outputs.package_name }}
# echo "PACKAGE_NAME=$PACKAGE_NAME" >> $GITHUB_ENV
# PACKAGE_STORAGE_URL=$PACKAGE_STORAGE_BASE_URL/$PACKAGE_NAME
# echo "PACKAGE_STORAGE_URL=$PACKAGE_STORAGE_URL" >> $GITHUB_ENV
# - name: Generate Manifests for Functional Tests
# run: |
# .github/workflows/utils/generate-manifests.sh ${{ github.workspace }}/helm ${{ github.workspace }}/configs/functional-tests manifests/functional-test
# - name: Generate Manifests for Performance Tests
# run: |
# .github/workflows/utils/generate-manifests.sh ${{ github.workspace }}/helm ${{ github.workspace }}/configs/performance-tests manifests/performance-test
# - name: Generate Manifests for Integration Tests
# run: |
# .github/workflows/utils/generate-ansible-manifests.sh ${{ github.workspace }}/ansible manifests/int-test
# cp ${{ github.workspace }}/configs/int-tests/* manifests/int-test/
# env:
# CONFIG_FILE: app-config.sh
# COMMAND: sample

# - name: Create PR
# run: |
# .github/workflows/utils//create-pr.sh -s ${{ github.workspace }}/manifests -d . -r ${{ secrets.MANIFESTS_REPO }} -b dev -i ${{ github.run_number }} -t ${{ secrets.MANIFESTS_TOKEN }} -m N

# Deploy_To_Stage:
# runs-on: ubuntu-latest
# needs: [Build_Push_Image, Deploy_To_Dev]
# environment: stage
# steps:
# - name: Checkout Source
# uses: actions/[email protected]
# - name: Checkout Configs
# uses: actions/[email protected]
# with:
# ref: stage-configs
# path: configs
# - name: Read Image Tags
# run: |
# IMAGE_TAG=${{ needs.Build_Push_Image.outputs.image_tag }}
# echo "IMAGE_TAG=$IMAGE_TAG" >> $GITHUB_ENV
# VERSION=$IMAGE_TAG
# echo "VERSION=$VERSION" >> $GITHUB_ENV
# - name: Read Package Name
# run: |
# PACKAGE_NAME=${{ needs.Build_Push_Image.outputs.package_name }}
# echo "PACKAGE_NAME=$PACKAGE_NAME" >> $GITHUB_ENV
# PACKAGE_STORAGE_URL=$PACKAGE_STORAGE_BASE_URL/$PACKAGE_NAME
# echo "PACKAGE_STORAGE_URL=$PACKAGE_STORAGE_URL" >> $GITHUB_ENV
# - name: Generate Manifests for UAT
# run: |
# .github/workflows/utils/generate-manifests.sh ${{ github.workspace }}/helm ${{ github.workspace }}/configs/uat-tests manifests/uat-test
# - name: Generate Manifests for Integration Tests
# run: |
# .github/workflows/utils/generate-ansible-manifests.sh ${{ github.workspace }}/ansible manifests/int-test
# cp ${{ github.workspace }}/configs/int-tests/* manifests/int-test/
# env:
# CONFIG_FILE: app-config.sh
# COMMAND: sample
# - name: Create PR
# run: |
# .github/workflows/utils//create-pr.sh -s ${{ github.workspace }}/manifests -d . -r ${{ secrets.MANIFESTS_REPO }} -b stage -i ${{ github.run_number }} -t ${{ secrets.MANIFESTS_TOKEN }} -m N



97 changes: 0 additions & 97 deletions .github/workflows/cicd.yaml

This file was deleted.

14 changes: 14 additions & 0 deletions .github/workflows/utils/generate-ansible-manifests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.

#!/bin/bash
echo $1
echo $2

set -euo pipefail

mkdir -p $2

# Substitute env variables
for file in `find $1 -type f \( -name "*.yml" \)`; do envsubst <"$file" > "$2/${file##*/}"; done

20 changes: 20 additions & 0 deletions Dockerfile-fpm
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
FROM ruby:2.5
RUN gem install --quiet --no-document fpm

ARG binary_name
ARG deb_package_name
ARG version_string
ARG deb_package_description

RUN mkdir /deb-package
ADD $binary_name /deb-package/
RUN mkdir dpkg-source
WORKDIR dpkg-source
RUN fpm --output-type deb \
--input-type dir --chdir /deb-package \
--prefix /usr/bin --name $binary_name \
--version $version_string \
--description '${deb_package_description}' \
-p ${deb_package_name}-${version_string}.deb \
$binary_name && cp *.deb /deb-package/
CMD ["/bin/bash"]
12 changes: 12 additions & 0 deletions ansible/install.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
- hosts: localhost
tasks:
- debug: msg="Install application"
- name: install application
ansible.builtin.import_tasks: /opt/kalypso/install-deb-package.yml
vars:
package_name: $PACKAGE_NAME
package_storage_url: $PACKAGE_STORAGE_URL
app_config_file: $CONFIG_FILE
command: $COMMAND
args: "$ARGS"
Loading

0 comments on commit 76ce2ab

Please sign in to comment.