From 9b293f71e8db1ba9fbffa1f71ccb1c0babdfec24 Mon Sep 17 00:00:00 2001
From: lijianguo <lijianguo@zhumengyuan.com>
Date: Thu, 28 Jan 2021 10:10:11 +0800
Subject: [PATCH] chore(CICD): use drone

---
 .drone/.drone.yml    | 155 +++++++++++++++++++++++++++++++++++++++++++
 .drone/manifest.tmpl |  18 +++++
 README.md            |   2 +-
 3 files changed, 174 insertions(+), 1 deletion(-)
 create mode 100644 .drone/.drone.yml
 create mode 100644 .drone/manifest.tmpl

diff --git a/.drone/.drone.yml b/.drone/.drone.yml
new file mode 100644
index 0000000..03594a9
--- /dev/null
+++ b/.drone/.drone.yml
@@ -0,0 +1,155 @@
+kind: pipeline
+type: docker
+name: linux-amd64
+
+platform:
+  arch: amd64
+  os: linux
+
+steps:
+  - name: test
+    image: docker.io/library/docker:dind
+    pull: if-not-exists
+    privileged: true
+    commands:
+    - nohup dockerd &
+    - apk add make bash curl
+    - make docker-build test
+    environment:
+      VERSION: ${DRONE_TAG:-latest}-linux-amd64
+      DEV_REGISTRY: ${DEV_REGISTRY:-docker.io}
+      DRYCC_REGISTRY: ${DRYCC_REGISTRY:-docker.io}
+    when:
+      event:
+        - push
+        - tag
+        - pull_request
+
+  - name: publish
+    image: docker.io/library/docker:dind
+    pull: if-not-exists
+    privileged: true
+    commands:
+    - nohup dockerd &
+    - apk add make bash curl
+    - echo $DOCKER_PASSWORD | docker login --username $DOCKER_USERNAME --password-stdin
+    - make docker-build docker-immutable-push
+    environment:
+      VERSION: ${DRONE_TAG:-latest}-linux-amd64
+      DEV_REGISTRY:
+        from_secret: dev_registry
+      DRYCC_REGISTRY:
+        from_secret: drycc_registry
+      DOCKER_USERNAME:
+        from_secret: docker_username
+      DOCKER_PASSWORD:
+        from_secret: docker_password
+    when:
+      event:
+        - push
+        - tag
+
+trigger:
+  event:
+    - push
+    - tag
+    - pull_request
+
+---
+kind: pipeline
+type: docker
+name: linux-arm64
+
+platform:
+  arch: arm64
+  os: linux
+
+steps:
+  - name: publish
+    image: docker.io/library/docker:dind
+    pull: if-not-exists
+    privileged: true
+    commands:
+    - nohup dockerd &
+    - apk add make bash curl
+    - echo $DOCKER_PASSWORD | docker login --username $DOCKER_USERNAME --password-stdin
+    - make docker-build docker-immutable-push
+    environment:
+      VERSION: ${DRONE_TAG:-latest}-linux-arm64
+      DEV_REGISTRY:
+        from_secret: dev_registry
+      DRYCC_REGISTRY:
+        from_secret: drycc_registry
+      DOCKER_USERNAME:
+        from_secret: docker_username
+      DOCKER_PASSWORD:
+        from_secret: docker_password
+
+trigger:
+  event:
+    - push
+    - tag
+
+---
+kind: pipeline
+type: docker
+name: manifest
+
+steps:
+  - name: generate manifest
+    image: docker.io/library/alpine
+    pull: if-not-exists
+    commands:
+      - sed -i "s/docker.io/$${DRYCC_REGISTRY}/g" .drone/manifest.tmpl
+    environment:
+      DRYCC_REGISTRY:
+        from_secret: drycc_registry
+
+  - name: publish
+    image: plugins/manifest
+    settings:
+      spec: .drone/manifest.tmpl
+      username:
+        from_secret: docker_username
+      password:
+        from_secret: docker_password
+    environment:
+      DEV_REGISTRY:
+        from_secret: dev_registry
+      DRYCC_REGISTRY:
+        from_secret: drycc_registry
+
+trigger:
+  event:
+    - push
+    - tag
+
+depends_on:
+  - linux-amd64
+  - linux-arm64
+
+---
+kind: pipeline
+type: docker
+name: chart
+
+steps:
+  - name: generate chart
+    image: docker.io/drycc/python-dev
+    commands:
+    - IMAGE_TAG=$([ ! -z $DRONE_TAG ] && echo ${DRONE_TAG:1} || echo \"canary\")
+    - sed -i "s/image_tag:\ \"canary\"/image_tag:\ $IMAGE_TAG/g" charts/registry/values.yaml
+    - helm package charts/registry --version ${DRONE_TAG:-v1.0.0}
+    - curl -u $CHARTMUSEUM_USERNAME:$CHARTMUSEUM_PASSWORD -F chart=@registry-${DRONE_TAG:-v1.0.0}.tgz "$CHARTMUSEUM_API/api/$([ -z $DRONE_TAG ] && echo testing || echo stable)/charts"
+    environment:
+      CHARTMUSEUM_USERNAME:
+        from_secret: chartmuseum_username
+      CHARTMUSEUM_PASSWORD:
+        from_secret: chartmuseum_password
+      CHARTMUSEUM_API:
+        from_secret: chartmuseum_api
+
+trigger:
+  event:
+    - push
+    - tag
diff --git a/.drone/manifest.tmpl b/.drone/manifest.tmpl
new file mode 100644
index 0000000..6b5a36e
--- /dev/null
+++ b/.drone/manifest.tmpl
@@ -0,0 +1,18 @@
+image: docker.io/drycc/registry:{{#if build.tag}}{{trimPrefix "v" build.tag}}{{else}}canary{{/if}}
+{{#if build.tags}}
+tags:
+{{#each build.tags}}
+  - {{this}}
+{{/each}}
+{{/if}}
+manifests:
+  -
+    image: docker.io/drycc/registry:{{#if build.tag}}{{build.tag}}-{{else}}latest-{{/if}}linux-amd64
+    platform:
+      architecture: amd64
+      os: linux
+  -
+    image: docker.io/drycc/registry:{{#if build.tag}}{{build.tag}}-{{else}}latest-{{/if}}linux-arm64
+    platform:
+      architecture: arm64
+      os: linux
diff --git a/README.md b/README.md
index 228d415..d3c5a7a 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,6 @@
 # Drycc Registry v2
 
-[![Build Status](https://travis-ci.org/drycc/registry.svg?branch=main)](https://travis-ci.org/drycc/registry)
+[![Build Status](https://drone.drycc.cc/api/badges/drycc/registry/status.svg)](https://drone.drycc.cc/drycc/registry)
 [![Go Report Card](https://goreportcard.com/badge/github.com/drycc/registry)](https://goreportcard.com/report/github.com/drycc/registry)
 
 
