From 383fbd12bcf0be0ed6f7b3532ea7b70759fb4908 Mon Sep 17 00:00:00 2001 From: Timo Welde Date: Fri, 6 Nov 2020 18:17:52 +0100 Subject: [PATCH 1/2] feat: deploy to kubernetes --- .github/workflows/kube-dev.yml | 100 +++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 .github/workflows/kube-dev.yml diff --git a/.github/workflows/kube-dev.yml b/.github/workflows/kube-dev.yml new file mode 100644 index 0000000..595321a --- /dev/null +++ b/.github/workflows/kube-dev.yml @@ -0,0 +1,100 @@ +name: Deploy to Amazon EKS + +on: + push: + branches: + - develop + - tw-792-kubernetes + +env: + ECR_REPOSITORY: kilt/prototype-services + ECR_IMAGE_TAG: latest-develop + SHA_IMAGE_TAG: ${{ github.sha }} + KUBECONFIG: '${{ github.workspace }}/.kube/kubeconfig' + +jobs: + deploy: + name: Deploy + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v1 + + - name: Configure AWS credentials + uses: aws-actions/configure-aws-credentials@v1 + with: + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + aws-region: eu-central-1 + + - name: Login to Amazon ECR + id: login-ecr + uses: aws-actions/amazon-ecr-login@v1 + + - name: set sdk dependency to 'latest' & set up .npmrc to connect to github packages + run: | + echo $(jq '.dependencies."@kiltprotocol/sdk-js"="latest"' package.json) > package.json + mv -f .npmrc.github .npmrc + + - name: Build, tag, and push image to Amazon ECR + id: build-image + env: + ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} + run: | + # Build a docker container and + # push it to ECR so that it can + # be deployed to ECS. + docker build \ + -t $ECR_REGISTRY/$ECR_REPOSITORY:$ECR_IMAGE_TAG \ + -t $ECR_REGISTRY/$ECR_REPOSITORY:$SHA_IMAGE_TAG \ + --build-arg NODE_AUTH_TOKEN=${{ secrets.GITHUB_TOKEN }} \ + . + docker push $ECR_REGISTRY/$ECR_REPOSITORY:$ECR_IMAGE_TAG + docker push $ECR_REGISTRY/$ECR_REPOSITORY:$SHA_IMAGE_TAG + echo "::set-output name=image::$ECR_REGISTRY/$ECR_REPOSITORY:$ECR_IMAGE_TAG" + echo "::set-output name=image-sha::$ECR_REGISTRY/$ECR_REPOSITORY:$SHA_IMAGE_TAG" + + - name: Configure Kubernetes + run: | + mkdir -p '${{ github.workspace }}/.kube' \ + && echo '${{ secrets.KUBE_CONFIG}}' | base64 -d > $KUBECONFIG + + - name: Set new image + env: + IMAGE: ${{ steps.build-image.outputs.image-sha }} + run: | + kubectl -n devnet set image deployment/services-deployment services-container=$IMAGE + + publish_to_docker: + name: Publish develop image to docker + needs: deploy + runs-on: ubuntu-latest + + steps: + - name: Configure AWS credentials + uses: aws-actions/configure-aws-credentials@v1 + with: + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + aws-region: eu-central-1 + + - name: Login to Amazon ECR + id: login-ecr + uses: aws-actions/amazon-ecr-login@v1 + + - name: Login to Docker Hub + env: + DOCKER_USER: ${{ secrets.DOCKER_USER }} + DOCKER_PASS: ${{ secrets.DOCKER_PASS }} + run: | + echo $DOCKER_PASS | docker login --username=$DOCKER_USER --password-stdin + - name: Tag and push dev image to Docker Hub + env: + ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} + DOCKER_REPOSITORY: kiltprotocol/demo-services + DOCKER_IMAGE_TAG: develop + run: | + docker pull $ECR_REGISTRY/$ECR_REPOSITORY:$ECR_IMAGE_TAG + docker tag $ECR_REGISTRY/$ECR_REPOSITORY:$ECR_IMAGE_TAG $DOCKER_REPOSITORY:$DOCKER_IMAGE_TAG + docker push $DOCKER_REPOSITORY:$DOCKER_IMAGE_TAG \ No newline at end of file From f4eaac56edab14c55abbc63fabceb7baec488fa9 Mon Sep 17 00:00:00 2001 From: Timo Welde Date: Sat, 7 Nov 2020 00:46:13 +0100 Subject: [PATCH 2/2] feat: prepare for merge --- .github/workflows/aws-dev.yml | 122 --------------------------------- .github/workflows/kube-dev.yml | 1 - 2 files changed, 123 deletions(-) delete mode 100644 .github/workflows/aws-dev.yml diff --git a/.github/workflows/aws-dev.yml b/.github/workflows/aws-dev.yml deleted file mode 100644 index 758e642..0000000 --- a/.github/workflows/aws-dev.yml +++ /dev/null @@ -1,122 +0,0 @@ -# This workflow will build and push a new container image to Amazon ECR, -# and then will deploy a new task definition to Amazon ECS, on every push -# to the master branch. -# -# To use this workflow, you will need to complete the following set-up steps: -# -# 1. Create an ECR repository to store your images. -# For example: `aws ecr create-repository --repository-name my-ecr-repo --region us-east-2`. -# Replace the value of `ECR_REPOSITORY` in the workflow below with your repository's name. -# Replace the value of `aws-region` in the workflow below with your repository's region. -# -# 2. Create an ECS task definition, an ECS cluster, and an ECS service. -# For example, follow the Getting Started guide on the ECS console: -# https://us-east-2.console.aws.amazon.com/ecs/home?region=us-east-2#/firstRun -# Replace the values for `service` and `cluster` in the workflow below with your service and cluster names. -# -# 3. Store your ECS task definition as a JSON file in your repository. -# The format should follow the output of `aws ecs register-task-definition --generate-cli-skeleton`. -# Replace the value of `task-definition` in the workflow below with your JSON file's name. -# Replace the value of `container-name` in the workflow below with the name of the container -# in the `containerDefinitions` section of the task definition. -# -# 4. Store an IAM user access key in GitHub Actions secrets named `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY`. -# See the documentation for each action used below for the recommended IAM policies for this IAM user, -# and best practices on handling the access key credentials. - -on: - push: - branches: - - develop - -name: Deploy to Amazon ECS - -env: - ECR_REPOSITORY: kilt/prototype-services - ECR_IMAGE_TAG: latest-develop - -jobs: - deploy: - name: Deploy - runs-on: ubuntu-latest - - steps: - - name: Checkout - uses: actions/checkout@v1 - - - name: Configure AWS credentials - uses: aws-actions/configure-aws-credentials@v1 - with: - aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} - aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} - aws-region: eu-central-1 - - - name: Login to Amazon ECR - id: login-ecr - uses: aws-actions/amazon-ecr-login@v1 - - - name: set sdk dependency to 'latest' & set up .npmrc to connect to github packages - run: | - echo $(jq '.dependencies."@kiltprotocol/sdk-js"="latest"' package.json) > package.json - mv -f .npmrc.github .npmrc - - - name: Build, tag, and push image to Amazon ECR - id: build-image - env: - ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} - run: | - # Build a docker container and - # push it to ECR so that it can - # be deployed to ECS. - docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$ECR_IMAGE_TAG --build-arg NODE_AUTH_TOKEN=${{ secrets.GITHUB_TOKEN }} . - docker push $ECR_REGISTRY/$ECR_REPOSITORY:$ECR_IMAGE_TAG - echo "::set-output name=image::$ECR_REGISTRY/$ECR_REPOSITORY:$ECR_IMAGE_TAG" - - - name: Fill in the new image ID in the Amazon ECS task definition - id: task-def - uses: aws-actions/amazon-ecs-render-task-definition@v1 - with: - task-definition: task-definition.json - container-name: demo-services - image: ${{ steps.build-image.outputs.image }} - - - name: Deploy Amazon ECS task definition - uses: aws-actions/amazon-ecs-deploy-task-definition@v1 - with: - task-definition: ${{ steps.task-def.outputs.task-definition }} - service: demo-services - cluster: kilt-devnet - wait-for-service-stability: true - - publish_to_docker: - name: Publish develop image to docker - needs: deploy - runs-on: ubuntu-latest - - steps: - - name: Configure AWS credentials - uses: aws-actions/configure-aws-credentials@v1 - with: - aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} - aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} - aws-region: eu-central-1 - - - name: Login to Amazon ECR - id: login-ecr - uses: aws-actions/amazon-ecr-login@v1 - - - name: Login to Docker Hub - env: - DOCKER_USER: ${{ secrets.DOCKER_USER }} - DOCKER_PASS: ${{ secrets.DOCKER_PASS }} - run: | - echo $DOCKER_PASS | docker login --username=$DOCKER_USER --password-stdin - - name: Tag and push dev image to Docker Hub - env: - ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} - DOCKER_REPOSITORY: kiltprotocol/demo-services - DOCKER_IMAGE_TAG: develop - run: | - docker pull $ECR_REGISTRY/$ECR_REPOSITORY:$ECR_IMAGE_TAG - docker tag $ECR_REGISTRY/$ECR_REPOSITORY:$ECR_IMAGE_TAG $DOCKER_REPOSITORY:$DOCKER_IMAGE_TAG - docker push $DOCKER_REPOSITORY:$DOCKER_IMAGE_TAG \ No newline at end of file diff --git a/.github/workflows/kube-dev.yml b/.github/workflows/kube-dev.yml index 595321a..1f6571c 100644 --- a/.github/workflows/kube-dev.yml +++ b/.github/workflows/kube-dev.yml @@ -4,7 +4,6 @@ on: push: branches: - develop - - tw-792-kubernetes env: ECR_REPOSITORY: kilt/prototype-services