Skip to content

NimTechnology

Trình bày các công nghệ CLOUD một cách dễ hiểu.

  • Kubernetes & Container
    • Docker
    • Kubernetes
      • Ingress
    • Helm Chart
    • Isito-EnvoyFilter
    • Apache Kafka
      • Kafka
      • Kafka Connect
      • Lenses
    • Vault
    • Longhorn – Storage
    • VictoriaMetrics
    • MetalLB
    • Kong Gateway
  • CI/CD
    • ArgoCD
    • ArgoWorkflows
    • Spinnaker
    • Jenkins
    • Harbor
    • TeamCity
    • Git
      • Bitbucket
  • Coding
    • Terraform
      • GCP – Google Cloud
      • AWS – Amazon Web Service
    • Golang
    • Laravel
    • Python
    • Jquery & JavaScript
    • Selenium
  • Log & Monitor
    • DataDog
    • Prometheus
    • Grafana
    • ELK
      • Kibana
      • Logstash
  • BareMetal
    • NextCloud
  • Toggle search form

[Kaniko/Bitbucket/ECR] Accomplish the workflow: CI by bitbucket pipeline, Kaniko build image and push image to ECR

Posted on November 13, 2022December 15, 2022 By nim No Comments on [Kaniko/Bitbucket/ECR] Accomplish the workflow: CI by bitbucket pipeline, Kaniko build image and push image to ECR

Mình cũng đã có 1 vài bài nói về kaniko và run kaniko trên k8s để build image

Hôm này chúng ta sẽ đến 1 bài là:
CI bằng bitbucket-pipeline
Build image bằng Kaniko
Sau đó push image lên ECR của AWS.

Contents

  • 1) design bitbucket-pipelines
  • 2) Kaniko push image to ECR
  • Kaniko push image to Dockerhub or Harbor.

1) design bitbucket-pipelines

Đầu tiên mình có file bitbucket-pipelines.yml

pipelines:
  branches:
    master:
      - step:
          name: prepare Aws Credentials
          script:
            - AWS_CREDENTIAL_FILE=credentials
            - echo "[default]"                              > $AWS_CREDENTIAL_FILE
            - echo "aws_access_key_id=${AWS_ACCESS_KEY_ID}"         >> $AWS_CREDENTIAL_FILE
            - echo "aws_secret_access_key=${AWS_SECRET_ACCESS_KEY}" >> $AWS_CREDENTIAL_FILE
          artifacts:
            - credentials
      - step:
          name: Build image
          script:
            - |
              docker run \
              -v $BITBUCKET_CLONE_DIR/credentials:/root/.aws/credentials \
              -v $BITBUCKET_CLONE_DIR:/workspace \
              gcr.io/kaniko-project/executor:debug \
              --dockerfile=/workspace/coding/nim-commit/Dockerfile \
              --context=/workspace/coding/nim-commit \
              --destination=250887682577.dkr.ecr.us-east-1.amazonaws.com/nim-commit:$BITBUCKET_BUILD_NUMBER \
              --use-new-run
          services:
              - docker

2) Kaniko push image to ECR

Đầu tiền mình sẽ cần phải nắm được làm sao để kaniko có thể push lên ECR:

https://github.com/GoogleContainerTools/kaniko#pushing-to-amazon-ecr

Mình chọn cách là tạo file credentials và mount nó vào folder /root/.aws/

Tiếp theo mình dụng artifacts của bitbucket-pipeline để sử dụng nó ở nhiều steps

phần sau là push code lên và bitbucket sẽ build cho cúng ta.

OK giở recheck là image đã được push lên ecr chưa?

Kaniko push image to Dockerhub or Harbor.

bạn đi vào project và tạo account robot

download file về

echo -n 'USER_NAME:PASS_WORD' | base64

echo -n 'robot$nim+kaniko:uS0QMTmDXfBuGMgecExxxxxxxxxx' | base64
cm9ib3Qra2FuaWtvOnVTMFFNVG1EWGZCdUdNZ2VjRTdwxxxxxxxx==

encode base64 hay encrypt base64

Bạn cũng cần để ý kĩ mình sử dụng ” chứ sử dụng “” là sẽ bị lỗi.

Hoặc cách khác là bạn login rồi copy nội dụng trong file .docker/config.json

Sau khi có tocken thì bạn tạo content cho file config.json

config.json
>>>>>>

{
  "auths": {
    "docker.nimtechnology.com": {
      "auth": "cm9ib3QkbmltK2thbmlrbzp1UzBRTVRtRFhmQnVHTWdlY0U3cGFxxxxxxxxxxxxxxxxx=="
    }
  }
}

giờ bạn tạo file bitbucket-pipelines.yml

pipelines:
  branches:
    master: 
      - step:
          name: prepare Harbor Credentials
          script:
            - HARBOR_CREDENTIAL_FILE=config.json
            - echo "${HARBOR_CREDENTIAL}"       > $HARBOR_CREDENTIAL_FILE
          artifacts:
            - config.json
      - step:
          name: Build image
          script:
            - cat $BITBUCKET_CLONE_DIR/config.json
            - |
              docker run \
              -v $BITBUCKET_CLONE_DIR/config.json:/kaniko/.docker/config.json:ro \
              -v $BITBUCKET_CLONE_DIR:/workspace \
              gcr.io/kaniko-project/executor:debug \
              --dockerfile=/workspace/coding/nim-commit/Dockerfile \
              --context=/workspace/coding/nim-commit \
              --destination=docker.nimtechnology.com/nim/nim-commit:$BITBUCKET_BUILD_NUMBER \
              --use-new-run
          services:
              - docker
AWS - Amazon Web Service, Bitbucket, CI/CD

Post navigation

Previous Post: [JetBrains] JetBrains Students! Chỉ có 80 ngàn/ 1 năm
Next Post: [OpenVPN] How to install OpenVPN system

More Related Articles

[Terraform] – Terraform Beginner – Lesson 5: Terraform Provisioners and creating EC2 AWS - Amazon Web Service
[AWS] EKS IAM Roles for Service Accounts (IRSA) using Terraform AWS - Amazon Web Service
[csi-driver-smb] Providing PVC with type ReadWriteMany base on SMB AWS - Amazon Web Service
[AWS] Provision AWS IAM Admin User as EKS Admin AWS - Amazon Web Service
[Terraform] – Terraform Beginner – Lesson 2: Working with Terraform. AWS - Amazon Web Service
[Terraform] Infrastructure Automation With Terraform – Lesson 1: Setup AWS AWS - Amazon Web Service

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Tham Gia Group DevOps nhé!
Để Nim có nhiều động lực ra nhiều bài viết.
Để nhận được những thông báo mới nhất.

Recent Posts

  • Experiences for IP Addresses Shortage on EKS Clusters March 29, 2023
  • [Talisman] Discover the sensitive information in your code. March 28, 2023
  • [Prometheus/Grafana] Install Prometheus and Grafana on ubuntu. March 27, 2023
  • [Kong Gateway] WebSocket connection failed March 26, 2023
  • [Nextcloud] Can’t download files to have a size bigger than 2Gi on NextCloud – RaspBerry March 24, 2023

Archives

  • March 2023
  • February 2023
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022
  • August 2022
  • July 2022
  • June 2022
  • May 2022
  • April 2022
  • March 2022
  • February 2022
  • January 2022
  • December 2021
  • November 2021
  • October 2021
  • September 2021
  • August 2021
  • July 2021
  • June 2021

Categories

  • BareMetal
    • NextCloud
  • CI/CD
    • ArgoCD
    • ArgoWorkflows
    • Git
      • Bitbucket
    • Harbor
    • Jenkins
    • Spinnaker
    • TeamCity
  • Coding
    • Golang
    • Jquery & JavaScript
    • Laravel
    • Python
    • Selenium
    • Terraform
      • AWS – Amazon Web Service
      • GCP – Google Cloud
  • Kubernetes & Container
    • Apache Kafka
      • Kafka
      • Kafka Connect
      • Lenses
    • Docker
    • Helm Chart
    • Isito-EnvoyFilter
    • Kong Gateway
    • Kubernetes
      • Ingress
    • Longhorn – Storage
    • MetalLB
    • Vault
    • VictoriaMetrics
  • Log & Monitor
    • DataDog
    • ELK
      • Kibana
      • Logstash
    • Grafana
    • Prometheus
  • Uncategorized
  • Admin

Copyright © 2023 NimTechnology.