Skip to content

Commit

Permalink
Merge branch 'main' into feature/add_vapor_implementation
Browse files Browse the repository at this point in the history
# Conflicts:
#	.gitignore
#	terraform/deployment/main.tf
#	terraform/deployment/variables.tf
#	terraform/ecr_repositories/variables.tf
  • Loading branch information
elmoritz committed Apr 12, 2024
2 parents f521cae + 90d84e9 commit a788e0a
Show file tree
Hide file tree
Showing 89 changed files with 4,888 additions and 669 deletions.
63 changes: 63 additions & 0 deletions .github/actions/k8s/build-deploy-quarkus/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: Build & Deploy Quarkus to k8s
description: Build & Deploy Quarkus to k8s (if running on deploy-branch)


inputs:
github-token:
required: true
description: Github Token
kube-config:
required: true
description: Kubernetes Config
working-directory:
default: .
description: working directory to be used
deploy-branch:
default: refs/heads/main
description: service will only be deployed for this branch


runs:
using: composite
steps:
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 21

- name: Setup Gradle
uses: gradle/actions/setup-gradle@v3

- name: assemble
shell: bash
working-directory: ${{ inputs.working-directory}}
run: ./gradlew assemble
env:
QUARKUS_HTTP_ROOT_PATH: /

- name: build container
shell: bash
working-directory: ${{ inputs.working-directory}}
run: ./gradlew assemble -Dquarkus.container-image.build=true
env:
QUARKUS_HTTP_ROOT_PATH: /

- uses: azure/k8s-set-context@v3
with:
method: kubeconfig
kubeconfig: ${{ inputs.kube-config }}

- name: push & deploy to k8s
shell: bash
working-directory: ${{ inputs.working-directory}}
if: ${{ github.ref == inputs.deploy-branch }}
run: |
./gradlew assemble -Dquarkus.kubernetes.deploy=true \
-Dquarkus.container-image.group=${{ github.repository_owner }}/${{ github.event.repository.name }} \
-Dquarkus.container-image.registry=ghcr.io \
-Dquarkus.container-image.additional-tags=${{ github.sha }} \
-Dquarkus.container-image.username=${{ github.actor }} \
-Dquarkus.container-image.password=${{ inputs.github-token }}
env:
QUARKUS_HTTP_ROOT_PATH: /
54 changes: 54 additions & 0 deletions .github/actions/k8s/deploy-postgres/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: Deploy Postgres with Anti Affinity
description: Deploy Postgres with Anti Affinity

inputs:
release-name:
required: true
description: release name for the helm chart
anti-affinity-value:
required: true
description: value to be used for the anti-affinity rule
kube-config:
required: true
description: kubernetes config file to connect to the cluster
namespace:
default: benchmarks
description: namespace to be used to install the chart
anti-affinity-key:
default: app.kubernetes.io/name
description: key to be used for the anti-affinity role
deploy-branch:
default: refs/heads/main
description: service will only be deployed for this branch


runs:
using: composite
steps:
- name: deploy postgres
uses: vimeda/[email protected]
if: ${{ github.ref == inputs.deploy-branch }}
with:
release: ${{ inputs.release-name }}
namespace: ${{ inputs.namespace }}
chart: oci://registry-1.docker.io/bitnamicharts/postgresql
values: |
global:
postgresql:
auth:
username: postgres
database: books-db
primary:
affinity:
podAntiAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- key: ${{ inputs.anti-affinity-key}}
operator: In
values:
- ${{ inputs.anti-affinity-value}}
topologyKey: "kubernetes.io/hostname"
env:
KUBECONFIG_FILE: ${{ inputs.kube-config }}
31 changes: 31 additions & 0 deletions .github/workflows/k8s-quarkus-reactive.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Quarkus Reactive Build & Deploy on k8s

on:
push:
branches:
- '**'
paths:
- bookstore-quarkus-reactive/**


jobs:
build:
name: build & push
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: build & deploy quarkus
uses: ./.github/actions/k8s/build-deploy-quarkus
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
kube-config: ${{ secrets.KUBECONFIG }}
working-directory: ./bookstore-quarkus-reactive

- name: deploy postgres
uses: ./.github/actions/k8s/deploy-postgres
with:
release-name: bookstore-quarkus-reactive
anti-affinity-value: bookstore-quarkus-reactive
kube-config: ${{ secrets.KUBECONFIG }}
31 changes: 31 additions & 0 deletions .github/workflows/k8s-quarkus-sync.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Quarkus Sync Build & Deploy on k8s

on:
push:
branches:
- '**'
paths:
- bookstore-quarkus-sync/**


jobs:
build:
name: build & push
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: build & deploy quarkus
uses: ./.github/actions/k8s/build-deploy-quarkus
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
kube-config: ${{ secrets.KUBECONFIG }}
working-directory: ./bookstore-quarkus-sync

- name: deploy postgres
uses: ./.github/actions/k8s/deploy-postgres
with:
release-name: bookstore-quarkus-sync
anti-affinity-value: bookstore-quarkus-sync
kube-config: ${{ secrets.KUBECONFIG }}
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ jobs:
- name: Build, tag, and push image to Amazon ECR
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: bookstore-quarkus
ECR_REPOSITORY: bookstore-quarkus-reactive
run: |
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$GITHUB_SHA -t $ECR_REGISTRY/$ECR_REPOSITORY .
docker push -a $ECR_REGISTRY/$ECR_REPOSITORY
working-directory: ./bookstore-quarkus
working-directory: ./bookstore-quarkus-reactive
35 changes: 35 additions & 0 deletions .github/workflows/publish-rust-rocket-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Publish RustRocket image to ECR

on:
push:
branches:
- main

jobs:
publish:
name: Publish RustRocket Image
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1-node16
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: eu-west-1

- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@261a7de32bda11ba01f4d75c4ed6caf3739e54be

- name: Build, tag, and push image to Amazon ECR
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: bookstore-rocketrs
run: |
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$GITHUB_SHA -t $ECR_REGISTRY/$ECR_REPOSITORY .
docker push -a $ECR_REGISTRY/$ECR_REPOSITORY
working-directory: ./bookstore-rocketrs
114 changes: 114 additions & 0 deletions .github/workflows/terraform-ecr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
name: "Terraform ECR"

on:
workflow_dispatch:
inputs:
repository-names:
description: "The name of all the new ECR repositories to be created e.g.: 'bookstore-quarkus-reactive,bookstore-springboot' "
type: "string"

jobs:
terraform:
name: "Terraform"
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8

- name: Setup Terraform
uses: hashicorp/setup-terraform@97112244d334d190527c2ffd571a09f16959bc94
with:
terraform_version: 1.5.7
cli_config_credentials_token: ${{ secrets.TF_API_TOKEN }}

- name: Terraform Format
id: fmt
run: terraform fmt -recursive -check
working-directory: ./terraform/ecr_repositories

- name: Terraform Init
id: init
run: terraform init
working-directory: ./terraform/ecr_repositories

- name: Terraform Validate
id: validate
run: terraform validate -no-color
working-directory: ./terraform/ecr_repositories

- name: Terraform Plan
id: plan
if: github.event_name == 'pull_request'
run: terraform plan -no-color -input=false
continue-on-error: true
working-directory: ./terraform/ecr_repositories

- uses: actions/github-script@d556feaca394842dc55e4734bf3bb9f685482fa0
if: github.event_name == 'pull_request'
env:
PLAN: "terraform\n${{ steps.plan.outputs.stdout }}"
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
// 1. Retrieve existing bot comments for the PR
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
})
const botComment = comments.find(comment => {
return comment.user.type === 'Bot' && comment.body.includes('Terraform Format and Style')
})
// 2. Prepare format of the comment
const output = `#### Terraform Format and Style 🖌\`${{ steps.fmt.outcome }}\`
#### Terraform Initialization ⚙️\`${{ steps.init.outcome }}\`
#### Terraform Validation 🤖\`${{ steps.validate.outcome }}\`
<details><summary>Validation Output</summary>
\`\`\`\n
${{ steps.validate.outputs.stdout }}
\`\`\`
</details>
#### Terraform Plan 📖\`${{ steps.plan.outcome }}\`
<details><summary>Show Plan</summary>
\`\`\`\n
${process.env.PLAN}
\`\`\`
</details>
*Pusher: @${{ github.actor }}, Action: \`${{ github.event_name }}\`, Working Directory: \`${{ env.tf_actions_working_dir }}\`, Workflow: \`${{ github.workflow }}\`*`;
// 3. If we have a comment, update it, otherwise create a new one
if (botComment) {
github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: botComment.id,
body: output
})
} else {
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: output
})
}
- name: Terraform Plan Status
if: steps.plan.outcome == 'failure'
run: exit 1
working-directory: ./terraform/ecr_repositories

- name: Terraform Apply
env:
REPOSITORY_NAMES: ${{ inputs.repository-names }}
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
run: terraform apply -auto-approve -input=false -var="repositories=[REPOSITORY_NAMES]"
working-directory: ./terraform/ecr_repositories
Loading

0 comments on commit a788e0a

Please sign in to comment.