Code Monkey home page Code Monkey logo

aws-codedeploy-service's Introduction

README

This is a Keptn Service Template written in GoLang.

Quick start:

  1. In case you want to contribute your service to keptn-sandbox or keptn-contrib, make sure you have read and understood the Contributing Guidelines.
  2. Click Use this template on top of the repository, or download the repo as a zip-file, extract it into a new folder named after the service you want to create (e.g., simple-service)
  3. Replace every occurrence of (docker) image names and tags from keptnsandbox/keptn-service-template-go to your docker organization and image name (e.g., yourorganization/simple-service)
  4. Replace every occurrence of keptn-service-template-go with the name of your service (e.g., simple-service)
  5. Optional (but recommended): Create a git repo (e.g., on github.com/your-username/simple-service)
  6. Àdapt the go.mod file and change example.com/ to the actual package name (e.g., github.com/your-username/simple-service)
  7. Add yourself to the CODEOWNERS file
  8. Initialize a git repository:
  • git init .
  • git add .
  • git commit -m "Initial Commit"
  1. Optional: Push your code an upstream git repo (e.g., GitHub) and adapt all links that contain github.com (e.g., to github.com/your-username/simple-service)
  2. Figure out whether your Kubernetes Deployment requires any RBAC rules or a different service-account, and adapt deploy/service.yaml accordingly (initial setup is serviceAccountName: keptn-default).
  3. Last but not least: Remove this intro within the README file and make sure the README file properly states what this repository is about

keptn-service-template-go

GitHub release (latest by date) Go Report Card

This implements a keptn-service-template-go for Keptn. If you want to learn more about Keptn visit us on keptn.sh

Compatibility Matrix

Please fill in your versions accordingly

Keptn Version Keptn-Service-Template-Go Docker Image
0.6.1 keptnsandbox/keptn-service-template-go:0.1.0
0.7.1 keptnsandbox/keptn-service-template-go:0.1.1
0.7.2 keptnsandbox/keptn-service-template-go:0.1.2

Installation

The keptn-service-template-go can be installed as a part of Keptn's uniform.

Deploy in your Kubernetes cluster

To deploy the current version of the keptn-service-template-go in your Keptn Kubernetes cluster, apply the deploy/service.yaml file:

kubectl apply -f deploy/service.yaml

This should install the keptn-service-template-go together with a Keptn distributor into the keptn namespace, which you can verify using

kubectl -n keptn get deployment keptn-service-template-go -o wide
kubectl -n keptn get pods -l run=keptn-service-template-go

Up- or Downgrading

Adapt and use the following command in case you want to up- or downgrade your installed version (specified by the $VERSION placeholder):

kubectl -n keptn set image deployment/keptn-service-template-go keptn-service-template-go=keptnsandbox/keptn-service-template-go:$VERSION --record

Uninstall

To delete a deployed keptn-service-template-go, use the file deploy/*.yaml files from this repository and delete the Kubernetes resources:

kubectl delete -f deploy/service.yaml

Development

Development can be conducted using any GoLang compatible IDE/editor (e.g., Jetbrains GoLand, VSCode with Go plugins).

It is recommended to make use of branches as follows:

  • master contains the latest potentially unstable version
  • release-* contains a stable version of the service (e.g., release-0.1.0 contains version 0.1.0)
  • create a new branch for any changes that you are working on, e.g., feature/my-cool-stuff or bug/overflow
  • once ready, create a pull request from that branch back to the master branch

When writing code, it is recommended to follow the coding style suggested by the Golang community.

Where to start

If you don't care about the details, your first entrypoint is eventhandlers.go. Within this file you can add implementation for pre-defined Keptn Cloud events.

To better understand all variants of Keptn CloudEvents, please look at the Keptn Spec.

If you want to get more insights into processing those CloudEvents or even defining your own CloudEvents in code, please look into main.go (specifically processKeptnCloudEvent), deploy/service.yaml, consult the Keptn docs as well as existing Keptn Core and Keptn Contrib services.

Common tasks

  • Build the binary: go build -ldflags '-linkmode=external' -v -o keptn-service-template-go
  • Run tests: go test -race -v ./...
  • Build the docker image: docker build . -t keptnsandbox/keptn-service-template-go:dev (Note: Ensure that you use the correct DockerHub account/organization)
  • Run the docker image locally: docker run --rm -it -p 8080:8080 keptnsandbox/keptn-service-template-go:dev
  • Push the docker image to DockerHub: docker push keptnsandbox/keptn-service-template-go:dev (Note: Ensure that you use the correct DockerHub account/organization)
  • Deploy the service using kubectl: kubectl apply -f deploy/
  • Delete/undeploy the service using kubectl: kubectl delete -f deploy/
  • Watch the deployment using kubectl: kubectl -n keptn get deployment keptn-service-template-go -o wide
  • Get logs using kubectl: kubectl -n keptn logs deployment/keptn-service-template-go -f
  • Watch the deployed pods using kubectl: kubectl -n keptn get pods -l run=keptn-service-template-go
  • Deploy the service using Skaffold: skaffold run --default-repo=your-docker-registry --tail (Note: Replace your-docker-registry with your DockerHub username; also make sure to adapt the image name in skaffold.yaml)

Testing Cloud Events

We have dummy cloud-events in the form of RFC 2616 requests in the test-events/ directory. These can be easily executed using third party plugins such as the Huachao Mao REST Client in VS Code.

Automation

GitHub Actions: Automated Pull Request Review

This repo uses reviewdog for automated reviews of Pull Requests.

You can find the details in .github/workflows/reviewdog.yml.

GitHub Actions: Unit Tests

This repo has automated unit tests for pull requests.

You can find the details in .github/workflows/tests.yml.

GH Actions/Workflow: Build Docker Images

This repo uses GH Actions and Workflows to test the code and automatically build docker images.

Docker Images are automatically pushed based on the configuration done in .ci_env and the two GitHub Secrets

  • REGISTRY_USER - your DockerHub username
  • REGISTRY_PASSWORD - a DockerHub access token (alternatively, your DockerHub password)

How to release a new version of this service

It is assumed that the current development takes place in the master branch (either via Pull Requests or directly).

To make use of the built-in automation using GH Actions for releasing a new version of this service, you should

  • branch away from master to a branch called release-x.y.z (where x.y.z is your version),
  • write release notes in the releasenotes/ folder,
  • check the output of GH Actions builds for the release branch,
  • verify that your image was built and pushed to DockerHub with the right tags,
  • update the image tags in [deploy/service.yaml], and
  • test your service against a working Keptn installation.

If any problems occur, fix them in the release branch and test them again.

Once you have confirmed that everything works and your version is ready to go, you should

  • create a new release on the release branch using the GitHub releases page, and
  • merge any changes from the release branch back to the master branch.

License

Please find more information in the LICENSE file.

aws-codedeploy-service's People

Watchers

 avatar  avatar  avatar

aws-codedeploy-service's Issues

Upgrade keptn/distributor to 0.8.4 for properly showing up at the integrations page in Keptn Bridge

In Keptn 0.8.4, the distributor will be extended with the functionality of registering itself as a Keptn uniform integration at the Keptn's Uniform API.

Related Video with short Tutorial (part of community meeting on June 17th): https://youtu.be/oZlf1v5qUvc?t=436

Goal: The integration/service should be visible in Keptn's Bridge Uniform screen:
image

If you have any questions, please reply to keptn/keptn#4418


To enable this feature, the following changes need to be made:

First, the image of the distributor container of the deployment needs to be set to keptn/distributor:0.8.4:

        - name: distributor
              image: keptn/distributor:0.8.4

Second, locate the env section of the distributor container:

        - name: distributor
          image: keptn/distributor:0.8.4
          resources: ...
          env:
            ...

and add the following environment variables:

            - name: VERSION
              valueFrom:
                fieldRef:
                  apiVersion: v1
                  fieldPath: 'metadata.labels[''app.kubernetes.io/version'']'
            - name: K8S_DEPLOYMENT_NAME
              valueFrom:
                fieldRef:
                  apiVersion: v1
                  fieldPath: 'metadata.labels[''app.kubernetes.io/name'']'
            - name: K8S_POD_NAME
              valueFrom:
                fieldRef:
                  apiVersion: v1
                  fieldPath: metadata.name
            - name: K8S_NAMESPACE
              valueFrom:
                fieldRef:
                  apiVersion: v1
                  fieldPath: metadata.namespace
            - name: K8S_NODE_NAME
              valueFrom:
                fieldRef:
                  apiVersion: v1
                  fieldPath: spec.nodeName

Last but not least, ensure that the labels app.kubernetes.io/version and app.kubernetes.name are available under spec.template.metadata.labels in the K8s deployment:

        app.kubernetes.io/name: dynatrace-service
        app.kubernetes.io/version: 0.14.1

You can find a complete example of deployment.yaml (or service.yaml) here: https://github.com/keptn-contrib/unleash-service/blob/release-0.3.2/deploy/service.yaml

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.