Skip to content

Commit 4ef72ae

Browse files
author
Pablo Collazo Collarte
authored
Merge pull request #71 from pablocollazoc/develop
Release 0.2.0
2 parents a073abf + 1610623 commit 4ef72ae

File tree

4 files changed

+242
-9
lines changed

4 files changed

+242
-9
lines changed

.github/ISSUE_TEMPLATE/MICROFLOW_EXECUTION.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,9 @@ body:
2424
- jdk-11
2525
validations:
2626
required: true
27+
- type: checkboxes
28+
attributes:
29+
label: Deploy the project
30+
options:
31+
- label: "yes"
32+

.github/workflows/dockerhub-release.yml

Lines changed: 0 additions & 5 deletions
This file was deleted.

.github/workflows/microflow-execution.yml

Lines changed: 200 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,20 @@ on:
2222
env:
2323
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2424
ISSUE_NUMBER: ${{ github.event.issue.number }}
25+
AWS_ACCOUNT_ID: ${{ secrets.AWS_ACCOUNT_ID }}
26+
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
27+
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
28+
AWS_REGION: ${{ secrets.AWS_REGION }}
2529

2630
jobs:
2731
retrieve-project:
2832
runs-on: ubuntu-20.04
2933
if: contains(join(github.event.label.name, ', '), 'microflow-start')
3034
outputs:
31-
PROJECT: ${{ steps.parsing.outputs.repo_name }}
35+
PROJECT: ${{ steps.parsing.outputs.repo }}
36+
PROJECT_NAME: ${{ steps.parsing.outputs.repo_name }}
3237
JDK: ${{ steps.parsing.outputs.jdk_version }}
38+
DEPLOY: ${{ steps.parsing.outputs.deploy }}
3339
steps:
3440
- name: Get information from body
3541
id: parsing
@@ -41,11 +47,15 @@ jobs:
4147
import re
4248
import sys
4349
rawform = str(os.environ['BODY'])
44-
repo_name = re.search(r"(### GitHub Repository\s*)(.*)", rawform).group(2)
50+
repo = re.search(r"(### GitHub Repository\s*)(.*)", rawform).group(2)
51+
repo_name = repo.split('/')[1]
4552
jdk_version = re.search(r"(### Java version used in the project\s*)(.*)", rawform).group(2)
53+
deploy = re.search(r"(### Deploy the project\s*)(.*)", rawform).group(2)
4654
55+
print(f'::set-output name=repo::{repo}')
4756
print(f'::set-output name=repo_name::{repo_name}')
4857
print(f'::set-output name=jdk_version::{jdk_version}')
58+
print(f'::set-output name=deploy::{deploy}')
4959
5060
- name: Return error
5161
if: ${{ always() && steps.parsing.outcome == 'failure' }}
@@ -68,7 +78,7 @@ jobs:
6878
uses: actions/checkout@v3
6979
id: checkout
7080
with:
71-
repository: ${{ steps.parsing.outputs.repo_name }}
81+
repository: ${{ steps.parsing.outputs.repo }}
7282
token: ${{ secrets.GITHUB_TOKEN }}
7383

7484
- name: Return error
@@ -272,7 +282,7 @@ jobs:
272282

273283
web-update:
274284
runs-on: ubuntu-20.04
275-
needs: [retrieve-project, sonarqube-scanner, checkstyle-spotbugs]
285+
needs: [sonarqube-scanner, checkstyle-spotbugs]
276286
steps:
277287
- name: Checkout to ghpages branch
278288
uses: actions/checkout@v3
@@ -355,3 +365,189 @@ jobs:
355365
run: |
356366
gh issue comment -R "${{github.repository}}" "$ISSUE_NUMBER" \
357367
--body "#### :heavy_check_mark: The project has build successfully"
368+
369+
- uses: actions/upload-artifact@v3
370+
with:
371+
name: packaged_project
372+
path: .
373+
374+
deploy:
375+
runs-on: ubuntu-20.04
376+
needs: [retrieve-project, build-test]
377+
if: ${{ needs.retrieve-project.outputs.DEPLOY == '- [X] yes' }}
378+
steps:
379+
- name: Get project
380+
id: get-project
381+
uses: actions/download-artifact@v3
382+
with:
383+
name: packaged_project
384+
385+
- name: Configure AWS credentials
386+
id: aws-login
387+
uses: aws-actions/configure-aws-credentials@v1
388+
with:
389+
aws-access-key-id: ${{ env.AWS_ACCESS_KEY_ID }}
390+
aws-secret-access-key: ${{ env.AWS_SECRET_ACCESS_KEY }}
391+
aws-region: ${{ env.AWS_REGION }}
392+
393+
- name: Return error
394+
if: ${{ always() && steps.aws-login.outcome == 'failure' }}
395+
run: |
396+
gh issue comment -R "${{github.repository}}" "$ISSUE_NUMBER" \
397+
--body "#### :x: Could not login in AWS
398+
Check the used aws credentials.
399+
400+
See the [workflow log](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}) for more details."
401+
402+
- name: Return success
403+
if: ${{ always() && steps.aws-login.outcome == 'success' }}
404+
run: |
405+
gh issue comment -R "${{github.repository}}" "$ISSUE_NUMBER" \
406+
--body "#### :heavy_check_mark: Logged in AWS successfully"
407+
408+
- name: Login to Amazon ECR
409+
id: login-ecr
410+
uses: aws-actions/amazon-ecr-login@v1
411+
412+
- name: Return error
413+
if: ${{ always() && steps.login-ecr.outcome == 'failure' }}
414+
run: |
415+
gh issue comment -R "${{github.repository}}" "$ISSUE_NUMBER" \
416+
--body "#### :x: Could not login in AWS ECR
417+
Check the used aws credentials.
418+
419+
See the [workflow log](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}) for more details."
420+
421+
- name: Return success
422+
if: ${{ always() && steps.login-ecr.outcome == 'success' }}
423+
run: |
424+
gh issue comment -R "${{github.repository}}" "$ISSUE_NUMBER" \
425+
--body "#### :heavy_check_mark: Logged in AWS ECR successfully"
426+
427+
- name: Build Images
428+
id: image-build
429+
run: |
430+
cd project
431+
docker-compose build
432+
433+
- name: Return error
434+
if: ${{ always() && steps.image-build.outcome == 'failure' }}
435+
run: |
436+
gh issue comment -R "${{github.repository}}" "$ISSUE_NUMBER" \
437+
--body "#### :x: The docker images that compose the project could not be build
438+
A docker-compose file is needed in the root of the project in order to build it.
439+
440+
See the [workflow log](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}) for more details."
441+
442+
- name: Return success
443+
if: ${{ always() && steps.image-build.outcome == 'success' }}
444+
run: |
445+
gh issue comment -R "${{github.repository}}" "$ISSUE_NUMBER" \
446+
--body "#### :heavy_check_mark: Docker images for every service were built successfully"
447+
448+
- name: Create ECR registries and push images
449+
id: create-ecr
450+
env:
451+
REGISTRY: ${{ steps.login-ecr.outputs.registry }}
452+
AWS_DEFAULT_REGION: $AWS_REGION
453+
run: |
454+
cd project
455+
docker image ls -f "reference=project_*" | awk '(NR>1) { print $1 }' > image_names
456+
cat image_names | xargs -I{} docker tag {} $REGISTRY/{}:latest
457+
cat image_names | xargs -I{} aws ecr create-repository \
458+
--repository-name {} \
459+
--image-scanning-configuration scanOnPush=true \
460+
--region $AWS_REGION
461+
cat image_names | xargs -I{} docker push $REGISTRY/{}:latest
462+
463+
- name: Return error
464+
if: ${{ always() && steps.create-ecr.outcome == 'failure' }}
465+
run: |
466+
gh issue comment -R "${{github.repository}}" "$ISSUE_NUMBER" \
467+
--body "#### :x: The docker images that compose the project could not be pushed to the AWS ECR
468+
Check the following requirements:
469+
- The used aws credentials have rights to create AWS ECR repositories.
470+
- The aws region used is the one where you want to deploy the project and the one where the cluster is located.
471+
472+
See the [workflow log](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}) for more details."
473+
474+
- name: Return success
475+
if: ${{ always() && steps.create-ecr.outcome == 'success' }}
476+
run: |
477+
gh issue comment -R "${{github.repository}}" "$ISSUE_NUMBER" \
478+
--body "#### :heavy_check_mark: Docker images were pushed to the private ECR registry successfully"
479+
480+
- name: Tag images with ECR prefix
481+
id: tag-images
482+
env:
483+
REGISTRY: ${{ steps.login-ecr.outputs.registry }}
484+
run: |
485+
sed -i "s|${{ needs.retrieve-project.outputs.PROJECT_NAME }}|$REGISTRY/project|g" project/kubernetes-manifest.yaml
486+
487+
- name: Return error
488+
if: ${{ always() && steps.tag-images.outcome == 'failure' }}
489+
run: |
490+
gh issue comment -R "${{github.repository}}" "$ISSUE_NUMBER" \
491+
--body "#### :x: The docker images that use the Kubernetes manifest could not be tagged with the ECR images
492+
Check the following requirements:
493+
- A Kubernetes manifest using the images composed by docker-compose exist in the root of the project (the image_name:tag should be the same).
494+
495+
See the [workflow log](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}) for more details."
496+
497+
- name: Return success
498+
if: ${{ always() && steps.tag-images.outcome == 'success' }}
499+
run: |
500+
gh issue comment -R "${{github.repository}}" "$ISSUE_NUMBER" \
501+
--body "#### :heavy_check_mark: Docker images were updated in the Kubernetes manifest successfully"
502+
503+
- name: Create VPC for EKS
504+
id: eks-vpc
505+
uses: aws-actions/[email protected]
506+
with:
507+
name: ${{ needs.retrieve-project.outputs.PROJECT_NAME }}-stack
508+
template: https://s3.us-west-2.amazonaws.com/amazon-eks/cloudformation/2020-10-29/amazon-eks-vpc-private-subnets.yaml
509+
no-fail-on-empty-changeset: "1"
510+
511+
- name: Create Kubernetes cluster
512+
id: eks-cluster
513+
run: |
514+
515+
rawoutput=$(aws cloudformation describe-stacks --stack-name ${{ needs.retrieve-project.outputs.PROJECT_NAME }}-stack |jq --raw-output '.Stacks[].Outputs[]')
516+
securitygroup=$(echo $rawoutput | jq --raw-output 'select(.OutputKey == "SecurityGroups").OutputValue')
517+
subnetids=$(echo $rawoutput | jq --raw-output 'select(.OutputKey == "SubnetIds").OutputValue')
518+
519+
aws eks create-cluster --region ${{ env.AWS_REGION }} --name ${{ needs.retrieve-project.outputs.PROJECT_NAME }}-cluster --kubernetes-version 1.22 \
520+
--role-arn arn:aws:iam::${{ env.AWS_ACCOUNT_ID }}:role/eksClusterRoleMicroflow \
521+
--resources-vpc-config subnetIds=$subnetids,securityGroupIds=$securitygroup
522+
523+
aws eks wait cluster-active --name ${{ needs.retrieve-project.outputs.PROJECT_NAME }}-cluster
524+
525+
aws eks create-nodegroup --cluster-name ${{ needs.retrieve-project.outputs.PROJECT_NAME }}-cluster --nodegroup-name ${{ needs.retrieve-project.outputs.PROJECT_NAME }}-nodegroup \
526+
--subnets $(echo $subnetids | sed 's/,/ /g') --node-role arn:aws:iam::${{ env.AWS_ACCOUNT_ID }}:role/microflowClusterNodeGroupsRole \
527+
--scaling-config minSize=2,maxSize=3,desiredSize=3 --remote-access ec2SshKey=microflow-key-pair
528+
529+
- name: Deploy to Kubernetes cluster
530+
id: deploy-k8s
531+
run: |
532+
533+
aws eks wait nodegroup-active --nodegroup-name ${{ needs.retrieve-project.outputs.PROJECT_NAME }}-nodegroup --cluster-name ${{ needs.retrieve-project.outputs.PROJECT_NAME }}-cluster
534+
535+
aws eks update-kubeconfig --region ${{ env.AWS_REGION }} --name ${{ needs.retrieve-project.outputs.PROJECT_NAME }}-cluster
536+
kubectl apply -f project/kubernetes-manifest.yaml
537+
538+
- name: Return error
539+
if: ${{ always() && steps.deploy-k8s.outcome == 'failure' }}
540+
run: |
541+
gh issue comment -R "${{github.repository}}" "$ISSUE_NUMBER" \
542+
--body "#### :x: The Kubernetes manifest could not be applied
543+
Check the following requirements:
544+
- Check the kubernetes manifest file, that should be named, **kubernetes-manifest.yml**
545+
546+
See the [workflow log](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}) for more details."
547+
548+
- name: Return success
549+
if: ${{ always() && steps.deploy-k8s.outcome == 'success' }}
550+
run: |
551+
gh issue comment -R "${{github.repository}}" "$ISSUE_NUMBER" \
552+
--body "#### :heavy_check_mark: The project was successfully deployed to the AWS EKS cluster"
553+

CHANGELOG.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,39 @@
1919
* [#47](https://github.com/pablocollazoc/microflow/pull/47): Merge pull request #46 from pablocollazoc/develop
2020
* [#51](https://github.com/pablocollazoc/microflow/pull/51): Merge pull request #50 from pablocollazoc/develop
2121
* [#50](https://github.com/pablocollazoc/microflow/pull/50): Release 0.2.0
22+
23+
24+
# Version: 0.1.0
25+
26+
27+
#### New Features
28+
29+
* [#2](https://github.com/pablocollazoc/microflow/pull/2) Creación del proyecto base
30+
* [#5](https://github.com/pablocollazoc/microflow/pull/5) Creación de servicio SonarQube
31+
* [#8](https://github.com/pablocollazoc/microflow/pull/8) Integración de SonarQube con Github Actions
32+
* [#9](https://github.com/pablocollazoc/microflow/pull/9) Correcta visualización del análisis por medio de GitHub Pages
33+
* [#16](https://github.com/pablocollazoc/microflow/pull/16) Introducción de los plugins Checkstyle y Spotbugs como medidas de calidad
34+
* [#18](https://github.com/pablocollazoc/microflow/pull/18) Mejora del proceso de creación de la interfaz web resumen
35+
* [#19](https://github.com/pablocollazoc/microflow/pull/19) Creación de flujo de lint de ficheros
36+
* [#21](https://github.com/pablocollazoc/microflow/pull/21) Workflow de detección de secretos en el repositorio
37+
* [#23](https://github.com/pablocollazoc/microflow/pull/23) Workflow de detección de secretos en el repositorio
38+
* [#25](https://github.com/pablocollazoc/microflow/pull/25) Ejecución de construcción y tests del proyecto
39+
* [#27](https://github.com/pablocollazoc/microflow/pull/27) Ejecución del flujo a través de una issue
40+
* [#30](https://github.com/pablocollazoc/microflow/pull/30) Update issue templates
41+
* [#32](https://github.com/pablocollazoc/microflow/pull/32) Ejecución del flujo a través de una issue
42+
* [#35](https://github.com/pablocollazoc/microflow/pull/35) Ejecución del flujo a través de una issue
43+
* [#37](https://github.com/pablocollazoc/microflow/pull/37) Ejecución del flujo a través de una issue
44+
* [#39](https://github.com/pablocollazoc/microflow/pull/39) Creación de servicio SonarQube
45+
* [#40](https://github.com/pablocollazoc/microflow/pull/40) Creación de flujo de release
46+
47+
#### Bug Fixes
48+
49+
* [#20](https://github.com/pablocollazoc/microflow/pull/20) fix workflow dispatch
50+
* [#29](https://github.com/pablocollazoc/microflow/pull/29) fix: updated added label in issue creation
51+
* [#34](https://github.com/pablocollazoc/microflow/pull/34) fix: jobs call
52+
53+
#### Unlabeled Changes
54+
55+
* [#41](https://github.com/pablocollazoc/microflow/pull/41) Release 0.1.0
56+
* [#42](https://github.com/pablocollazoc/microflow/pull/42) Revert "Release 0.1.0"
57+
* [#43](https://github.com/pablocollazoc/microflow/pull/43) Revert "Revert "Release 0.1.0""

0 commit comments

Comments
 (0)