Skip to content

Commit

Permalink
Added cart and order pipelines
Browse files Browse the repository at this point in the history
  • Loading branch information
PeppyDays committed Aug 29, 2023
1 parent 21156dc commit 3152c10
Show file tree
Hide file tree
Showing 6 changed files with 520 additions and 0 deletions.
101 changes: 101 additions & 0 deletions .github/workflows/coffee-cart-cd.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
on:
pull_request:
types:
- closed
paths:
- .github/workflows/coffee-cart-cd.yaml
- products/coffee/cart/**

name: Coffee Cart CD
run-name: Coffee Cart CD by @${{ github.actor }}

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
cancel-in-progress: true

env:
PRODUCT_NAME: coffee
SERVICE_NAME: cart
APPLICATION_PATH: products/coffee/cart/api
GITOPS_APPLICATION_PATH: gitops/applications/coffee/cart/api
IMAGE_REPOSITORY: ghcr.io/${{ github.repository_owner }}/coffee/cart/api

jobs:
build-and-push:
name: Build and Push
runs-on: ubuntu-latest
permissions:
id-token: write
contents: write
steps:
- name: Set Variables
id: set-vars
run: |
echo "IMAGE_REPOSITORY=`echo ${{ env.IMAGE_REPOSITORY }} | tr '[:upper:]' '[:lower:]'`" >> $GITHUB_ENV
echo "IMAGE_TAG=rc-`echo ${GITHUB_SHA::7}`" >> $GITHUB_ENV
- name: Checkout Application Code
uses: actions/checkout@v3
with:
sparse-checkout: |
${{ env.APPLICATION_PATH }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Log in to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GHCR_TOKEN }}
- name: Build and Push
uses: docker/build-push-action@v4
with:
context: ${{ env.APPLICATION_PATH }}
platforms: linux/amd64,linux/arm64
file: ${{ env.APPLICATION_PATH }}/Dockerfile
push: true
tags: |
${{ env.IMAGE_REPOSITORY }}:${{ env.IMAGE_TAG }}
${{ env.IMAGE_REPOSITORY }}:latest
cache-from: type=registry,ref=${{ env.IMAGE_REPOSITORY }}:cache
cache-to: type=registry,ref=${{ env.IMAGE_REPOSITORY }}:cache,mode=max
- name: Tag Image
run: |
git tag ${{ env.PRODUCT_NAME }}/${{ env.SERVICE_NAME }}/api/${{ env.IMAGE_TAG }}
git tag -f ${{ env.PRODUCT_NAME }}/${{ env.SERVICE_NAME }}/api/latest
git push origin --tags -f
deploy:
name: Deploy
needs: build-and-push
runs-on: ubuntu-latest
permissions:
id-token: write
contents: write
steps:
- name: Set Variables
id: set-vars
run: |
echo "IMAGE_TAG=rc-`echo ${GITHUB_SHA::7}`" >> $GITHUB_ENV
- name: Checkout GitOps Code
uses: actions/checkout@v3
with:
sparse-checkout: |
${{ env.GITOPS_APPLICATION_PATH }}
- name: Update Image Tag and Commit
run: |
pushd ${{ env.GITOPS_APPLICATION_PATH }}
yq -P -i '.image.tag = "${{ env.IMAGE_TAG }}"' values.yaml
git config --global user.email "[email protected]"
git config --global user.name "$GITHUB_ACTOR"
git add .
git commit -m "Update image :: ${{ env.PRODUCT_NAME }} :: ${{ env.SERVICE_NAME }} :: api :: ${{ env.IMAGE_TAG }}"
- name: Push Commited Files
uses: nick-fields/retry@v2
with:
timeout_seconds: 10
max_attempts: 5
retry_on: error
command: |
git pull --rebase
git push -u origin
56 changes: 56 additions & 0 deletions .github/workflows/coffee-cart-ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
on:
pull_request:
paths:
- .github/workflows/coffee-cart-ci.yaml
- products/coffee/cart/**

name: Coffee Cart CI
run-name: Coffee Cart CI by @${{ github.actor }}

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
cancel-in-progress: true

env:
APPLICATION_PATH: products/coffee/cart/api

jobs:
test:
name: Test
runs-on: ubuntu-latest
steps:
- name: Checkout Application Code
uses: actions/checkout@v3
with:
sparse-checkout: |
${{ env.APPLICATION_PATH }}
- name: Install poetry
run: pipx install poetry
- name: Set up Python Environment
uses: actions/setup-python@v4
with:
python-version: "3.11"
cache: "poetry"
- name: Install Dependencies
run: |
pushd ${{ env.APPLICATION_PATH }}
poetry env use 3.11
poetry install --with test --without dev
poetry install --only-root
- name: Run tests
run: |
pushd ${{ env.APPLICATION_PATH }}
make test
build:
name: Build
runs-on: ubuntu-latest
steps:
- name: Checkout Application Code
uses: actions/checkout@v3
with:
sparse-checkout: |
${{ env.APPLICATION_PATH }}
- name: Build
run: |
pushd ${{ env.APPLICATION_PATH }}
docker build . -t cart:latest
103 changes: 103 additions & 0 deletions .github/workflows/coffee-cart-md.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
on:
workflow_dispatch:

name: Coffee Cart MD
run-name: Coffee Cart MD by @${{ github.actor }}

concurrency:
group: ${{ github.workflow }}
cancel-in-progress: true

env:
PRODUCT_NAME: coffee
SERVICE_NAME: cart
MODULE_NAME: api
APPLICATION_PATH: products/coffee/cart/api
GITOPS_APPLICATION_PATH: gitops/applications/coffee/cart/api
IMAGE_REPOSITORY: ghcr.io/${{ github.repository_owner }}/coffee/cart/api

jobs:
build-and-push-in-branch:
name: Build and Push
runs-on: ubuntu-latest
if: ${{ github.ref_type == 'branch' }}
permissions:
id-token: write
contents: write
steps:
- name: Set Variables
id: set-vars
run: |
echo "IMAGE_REPOSITORY=`echo ${{ env.IMAGE_REPOSITORY }} | tr '[:upper:]' '[:lower:]'`" >> $GITHUB_ENV
echo "IMAGE_TAG=feature-`echo ${GITHUB_SHA::7}`" >> $GITHUB_ENV
- name: Checkout Application Code
uses: actions/checkout@v3
with:
sparse-checkout: |
${{ env.APPLICATION_PATH }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Log in to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GHCR_TOKEN }}
- name: Build and Push
uses: docker/build-push-action@v4
with:
context: ${{ env.APPLICATION_PATH }}
platforms: linux/amd64,linux/arm64
file: ${{ env.APPLICATION_PATH }}/Dockerfile
push: true
tags: |
${{ env.IMAGE_REPOSITORY }}:${{ env.IMAGE_TAG }}
cache-from: type=registry,ref=${{ env.IMAGE_REPOSITORY }}:cache
cache-to: type=registry,ref=${{ env.IMAGE_REPOSITORY }}:cache,mode=max
deploy:
name: Deploy
needs:
- build-and-push-in-branch
if: always() && !contains(needs.*.result, 'failure') && !contains(needs.*.result, 'cancelled')
runs-on: ubuntu-latest
permissions:
id-token: write
contents: write
steps:
- name: Set Variables
id: set-vars
run: |
if [[ ${{ github.ref_type }} == 'branch' ]]; then
export IMAGE_TAG=feature-`echo ${GITHUB_SHA::7}`
elif [[ ${{ github.ref_type }} == 'tag' && ${{ github.ref_name }} =~ .*latest ]]; then
export SHA=`gh api repos/${{ github.repository }}/git/refs/tags/${{ env.PRODUCT_NAME }}/${{ env.SERVICE_NAME }}/${{ env.MODULE_NAME }}/latest | jq -r '.object.sha'`
export IMAGE_TAG=${SHA::7}
else
export IMAGE_TAG=`echo ${{ github.ref_name }} | cut -d '/' -f4`
fi
echo "IMAGE_TAG=$IMAGE_TAG" >> $GITHUB_ENV
- name: Checkout GitOps Code
uses: actions/checkout@v3
with:
ref: main
sparse-checkout: |
${{ env.GITOPS_APPLICATION_PATH }}
- name: Update Image Tag and Commit
run: |
pushd ${{ env.GITOPS_APPLICATION_PATH }}
yq -P -i '.image.tag = "${{ env.IMAGE_TAG }}"' values.yaml
git config --global user.email "[email protected]"
git config --global user.name "$GITHUB_ACTOR"
git add .
git commit -m "Update image :: ${{ env.PRODUCT_NAME }} :: ${{ env.SERVICE_NAME }} :: api :: ${{ env.IMAGE_TAG }}"
- name: Push Committed Files
uses: nick-fields/retry@v2
with:
timeout_seconds: 10
max_attempts: 5
retry_on: error
command: |
git pull --rebase
git push -u origin
101 changes: 101 additions & 0 deletions .github/workflows/coffee-order-cd.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
on:
pull_request:
types:
- closed
paths:
- .github/workflows/coffee-order-cd.yaml
- products/coffee/order/**

name: Coffee Order CD
run-name: Coffee Order CD by @${{ github.actor }}

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
cancel-in-progress: true

env:
PRODUCT_NAME: coffee
SERVICE_NAME: order
APPLICATION_PATH: products/coffee/order/api
GITOPS_APPLICATION_PATH: gitops/applications/coffee/order/api
IMAGE_REPOSITORY: ghcr.io/${{ github.repository_owner }}/coffee/order/api

jobs:
build-and-push:
name: Build and Push
runs-on: ubuntu-latest
permissions:
id-token: write
contents: write
steps:
- name: Set Variables
id: set-vars
run: |
echo "IMAGE_REPOSITORY=`echo ${{ env.IMAGE_REPOSITORY }} | tr '[:upper:]' '[:lower:]'`" >> $GITHUB_ENV
echo "IMAGE_TAG=rc-`echo ${GITHUB_SHA::7}`" >> $GITHUB_ENV
- name: Checkout Application Code
uses: actions/checkout@v3
with:
sparse-checkout: |
${{ env.APPLICATION_PATH }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Log in to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GHCR_TOKEN }}
- name: Build and Push
uses: docker/build-push-action@v4
with:
context: ${{ env.APPLICATION_PATH }}
platforms: linux/amd64,linux/arm64
file: ${{ env.APPLICATION_PATH }}/Dockerfile
push: true
tags: |
${{ env.IMAGE_REPOSITORY }}:${{ env.IMAGE_TAG }}
${{ env.IMAGE_REPOSITORY }}:latest
cache-from: type=registry,ref=${{ env.IMAGE_REPOSITORY }}:cache
cache-to: type=registry,ref=${{ env.IMAGE_REPOSITORY }}:cache,mode=max
- name: Tag Image
run: |
git tag ${{ env.PRODUCT_NAME }}/${{ env.SERVICE_NAME }}/api/${{ env.IMAGE_TAG }}
git tag -f ${{ env.PRODUCT_NAME }}/${{ env.SERVICE_NAME }}/api/latest
git push origin --tags -f
deploy:
name: Deploy
needs: build-and-push
runs-on: ubuntu-latest
permissions:
id-token: write
contents: write
steps:
- name: Set Variables
id: set-vars
run: |
echo "IMAGE_TAG=rc-`echo ${GITHUB_SHA::7}`" >> $GITHUB_ENV
- name: Checkout GitOps Code
uses: actions/checkout@v3
with:
sparse-checkout: |
${{ env.GITOPS_APPLICATION_PATH }}
- name: Update Image Tag and Commit
run: |
pushd ${{ env.GITOPS_APPLICATION_PATH }}
yq -P -i '.image.tag = "${{ env.IMAGE_TAG }}"' values.yaml
git config --global user.email "[email protected]"
git config --global user.name "$GITHUB_ACTOR"
git add .
git commit -m "Update image :: ${{ env.PRODUCT_NAME }} :: ${{ env.SERVICE_NAME }} :: api :: ${{ env.IMAGE_TAG }}"
- name: Push Commited Files
uses: nick-fields/retry@v2
with:
timeout_seconds: 10
max_attempts: 5
retry_on: error
command: |
git pull --rebase
git push -u origin
Loading

0 comments on commit 3152c10

Please sign in to comment.