From b52f6ba1f19e0b47964837219d52b75b01f73eb1 Mon Sep 17 00:00:00 2001 From: nic-chen Date: Sun, 12 Jul 2020 10:11:01 +0800 Subject: [PATCH 1/7] update github actions for api ci cd --- .github/workflows/api_cd.yml | 40 ++++++++++++++++++++++++- .github/workflows/api_ci.yml | 57 ++++++++++++++++++++++++++++++++++++ .github/workflows/api_ut.yml | 18 ------------ api/conf/conf-ci.json | 19 ++++++++++++ 4 files changed, 115 insertions(+), 19 deletions(-) create mode 100644 .github/workflows/api_ci.yml delete mode 100644 .github/workflows/api_ut.yml create mode 100644 api/conf/conf-ci.json diff --git a/.github/workflows/api_cd.yml b/.github/workflows/api_cd.yml index a2e0cfbb4a..6e91270712 100644 --- a/.github/workflows/api_cd.yml +++ b/.github/workflows/api_cd.yml @@ -1,4 +1,4 @@ -name: API CD +name: API CI && CD on: push: @@ -8,9 +8,47 @@ on: jobs: build: runs-on: ubuntu-latest + + services: + etcd: + image: bitnami/etcd:3.3.13-r80 + ports: + - 2379:2379 + - 2380:2380 + env: + ALLOW_NONE_AUTHENTICATION: yes + + apisix: + image: johz/apisix:v1.4-github-action + env: + APISIX_ETCD_HOST: http://etcd:2379 + ports: + - 9080:9080 + + mysql: + image: mysql:8.0 + env: + MYSQL_ROOT_PASSWORD: 123456 + ports: + - '8888:3306' + options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 + + steps: - uses: actions/checkout@v2 + - name: setting up database + run: | + mysql -h 127.0.0.1 --port 8888 -u root -p123456 < ./api/script/db/schema.sql + + - name: use ci config + run: | + mv ./api/conf/conf-ci.json ./api/conf/conf.json + + - name: run test + uses: cedrickring/golang-action@1.5.2 + working-directory: ./api + - uses: Azure/docker-login@v1 with: login-server: apisixacr.azurecr.cn diff --git a/.github/workflows/api_ci.yml b/.github/workflows/api_ci.yml new file mode 100644 index 0000000000..821f1ad280 --- /dev/null +++ b/.github/workflows/api_ci.yml @@ -0,0 +1,57 @@ +name: API CI + +on: + push: + branches: + - master + pull_request: + branches: + - master + +jobs: + + run-test: + + runs-on: ubuntu-latest + + services: + etcd: + image: bitnami/etcd:3.3.13-r80 + ports: + - 2379:2379 + - 2380:2380 + env: + ALLOW_NONE_AUTHENTICATION: yes + + apisix: + image: johz/apisix:v1.4-github-action + env: + APISIX_ETCD_HOST: http://etcd:2379 + ports: + - 9080:9080 + + mysql: + image: mysql:8.0 + env: + MYSQL_ROOT_PASSWORD: 123456 + ports: + - '8888:3306' + options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 + + + steps: + + - uses: actions/checkout@v2 + + - name: setting up database + run: | + mysql -h 127.0.0.1 --port 8888 -u root -p123456 < ./api/script/db/schema.sql + + - name: use ci config + run: | + mv ./api/conf/conf-ci.json ./api/conf/conf.json + + - name: run test + uses: cedrickring/golang-action@1.5.2 + working-directory: ./api + diff --git a/.github/workflows/api_ut.yml b/.github/workflows/api_ut.yml deleted file mode 100644 index 2b3c4bb4e2..0000000000 --- a/.github/workflows/api_ut.yml +++ /dev/null @@ -1,18 +0,0 @@ -name: API unit test - -on: - push: - branches: - - master - - manager - pull_request: - branches: - - master - -jobs: - build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - name: use docker-compose in api - run: cd ./api && docker-compose up \ No newline at end of file diff --git a/api/conf/conf-ci.json b/api/conf/conf-ci.json new file mode 100644 index 0000000000..f6dc8db45a --- /dev/null +++ b/api/conf/conf-ci.json @@ -0,0 +1,19 @@ +{ + "conf":{ + "mysql":{ + "address": "mysql:3306", + "user": "root", + "password": "123456", + "maxConns": 50, + "maxIdleConns": 25, + "maxLifeTime": 10 + }, + "syslog":{ + "host": "localhost" + }, + "apisix":{ + "base_url": "http://apisix:9080/apisix/admin", + "api_key": "edd1c9f034335f136f87ad84b625c8f1" + } + } +} From b2a3bf674d082155c05e3760f7a78c257bfb2aa7 Mon Sep 17 00:00:00 2001 From: nic-chen Date: Sun, 12 Jul 2020 10:36:05 +0800 Subject: [PATCH 2/7] fix: working-directory --- .github/workflows/api_cd.yml | 11 ++++++++--- .github/workflows/api_ci.yml | 12 ++++++++---- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/.github/workflows/api_cd.yml b/.github/workflows/api_cd.yml index 6e91270712..03345cd0d8 100644 --- a/.github/workflows/api_cd.yml +++ b/.github/workflows/api_cd.yml @@ -45,9 +45,14 @@ jobs: run: | mv ./api/conf/conf-ci.json ./api/conf/conf.json - - name: run test - uses: cedrickring/golang-action@1.5.2 - working-directory: ./api + - name: setup go + uses: actions/setup-go@v1 + with: + go-version: '1.13' + + - run: | + cd ./api + go run test ./... - uses: Azure/docker-login@v1 with: diff --git a/.github/workflows/api_ci.yml b/.github/workflows/api_ci.yml index 821f1ad280..4ebe3d8ba0 100644 --- a/.github/workflows/api_ci.yml +++ b/.github/workflows/api_ci.yml @@ -51,7 +51,11 @@ jobs: run: | mv ./api/conf/conf-ci.json ./api/conf/conf.json - - name: run test - uses: cedrickring/golang-action@1.5.2 - working-directory: ./api - + - name: setup go + uses: actions/setup-go@v1 + with: + go-version: '1.13' + + - run: | + cd ./api + go run test ./... From e7fb0966f3d924d4539a61ecea4f7a3cb6747cc4 Mon Sep 17 00:00:00 2001 From: nic-chen Date: Sun, 12 Jul 2020 10:41:33 +0800 Subject: [PATCH 3/7] fix error --- .github/workflows/api_ci.yml | 4 ++-- .github/workflows/{api_cd.yml => api_cicd.yml} | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) rename .github/workflows/{api_cd.yml => api_cicd.yml} (97%) diff --git a/.github/workflows/api_ci.yml b/.github/workflows/api_ci.yml index 4ebe3d8ba0..773dea3c4c 100644 --- a/.github/workflows/api_ci.yml +++ b/.github/workflows/api_ci.yml @@ -57,5 +57,5 @@ jobs: go-version: '1.13' - run: | - cd ./api - go run test ./... + cd ./api + go test ./... diff --git a/.github/workflows/api_cd.yml b/.github/workflows/api_cicd.yml similarity index 97% rename from .github/workflows/api_cd.yml rename to .github/workflows/api_cicd.yml index 03345cd0d8..fa0c4f72e9 100644 --- a/.github/workflows/api_cd.yml +++ b/.github/workflows/api_cicd.yml @@ -51,8 +51,8 @@ jobs: go-version: '1.13' - run: | - cd ./api - go run test ./... + cd ./api + go test ./... - uses: Azure/docker-login@v1 with: From b0d6e0e91ac59352c6eb1f76226fd50b129725f1 Mon Sep 17 00:00:00 2001 From: nic-chen Date: Sun, 12 Jul 2020 10:51:17 +0800 Subject: [PATCH 4/7] fix: step name --- .github/workflows/api_ci.yml | 5 +++-- .github/workflows/api_cicd.yml | 10 ++++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/.github/workflows/api_ci.yml b/.github/workflows/api_ci.yml index 773dea3c4c..7a3c237038 100644 --- a/.github/workflows/api_ci.yml +++ b/.github/workflows/api_ci.yml @@ -56,6 +56,7 @@ jobs: with: go-version: '1.13' - - run: | - cd ./api + - name: run test + working-directory: ./api + run: | go test ./... diff --git a/.github/workflows/api_cicd.yml b/.github/workflows/api_cicd.yml index fa0c4f72e9..1344bd9396 100644 --- a/.github/workflows/api_cicd.yml +++ b/.github/workflows/api_cicd.yml @@ -50,8 +50,9 @@ jobs: with: go-version: '1.13' - - run: | - cd ./api + - name: run test + working-directory: ./api + run: | go test ./... - uses: Azure/docker-login@v1 @@ -59,8 +60,9 @@ jobs: login-server: apisixacr.azurecr.cn username: ${{ secrets.REGISTRY_USERNAME }} password: ${{ secrets.REGISTRY_PASSWORD }} - - - run: | + + - name: build and push docker image + run: | cd ./api docker build . -t apisixacr.azurecr.cn/managerapi:${{ github.sha }} docker push apisixacr.azurecr.cn/managerapi:${{ github.sha }} From 0f13d5d5b6219161f86a6b943fa90106caa01d22 Mon Sep 17 00:00:00 2001 From: nic-chen Date: Sun, 12 Jul 2020 10:56:06 +0800 Subject: [PATCH 5/7] fix: mysql config for github action --- api/conf/conf-ci.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/conf/conf-ci.json b/api/conf/conf-ci.json index f6dc8db45a..34283f35f4 100644 --- a/api/conf/conf-ci.json +++ b/api/conf/conf-ci.json @@ -1,7 +1,7 @@ { "conf":{ "mysql":{ - "address": "mysql:3306", + "address": "127.0.0.1:8888", "user": "root", "password": "123456", "maxConns": 50, From 2831df6872833ad70622dd55016cd15da6199d58 Mon Sep 17 00:00:00 2001 From: nic-chen Date: Sun, 12 Jul 2020 11:01:29 +0800 Subject: [PATCH 6/7] test --- .github/workflows/api_ci.yml | 2 +- api/conf/conf-ci.json | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/api_ci.yml b/.github/workflows/api_ci.yml index 7a3c237038..f93b0c04e8 100644 --- a/.github/workflows/api_ci.yml +++ b/.github/workflows/api_ci.yml @@ -35,7 +35,7 @@ jobs: env: MYSQL_ROOT_PASSWORD: 123456 ports: - - '8888:3306' + - '3306:3306' options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 diff --git a/api/conf/conf-ci.json b/api/conf/conf-ci.json index 34283f35f4..78f06fc020 100644 --- a/api/conf/conf-ci.json +++ b/api/conf/conf-ci.json @@ -1,7 +1,7 @@ { "conf":{ "mysql":{ - "address": "127.0.0.1:8888", + "address": "127.0.0.1:3306", "user": "root", "password": "123456", "maxConns": 50, @@ -12,7 +12,7 @@ "host": "localhost" }, "apisix":{ - "base_url": "http://apisix:9080/apisix/admin", + "base_url": "http://127.0.0.1:9080/apisix/admin", "api_key": "edd1c9f034335f136f87ad84b625c8f1" } } From fe850572b98cb1487f93815530897b41523187f1 Mon Sep 17 00:00:00 2001 From: nic-chen Date: Sun, 12 Jul 2020 11:09:50 +0800 Subject: [PATCH 7/7] use default config --- .github/workflows/api_ci.yml | 6 +----- .github/workflows/api_cicd.yml | 8 ++------ api/conf/conf-ci.json | 19 ------------------- 3 files changed, 3 insertions(+), 30 deletions(-) delete mode 100644 api/conf/conf-ci.json diff --git a/.github/workflows/api_ci.yml b/.github/workflows/api_ci.yml index f93b0c04e8..ec906daed6 100644 --- a/.github/workflows/api_ci.yml +++ b/.github/workflows/api_ci.yml @@ -45,11 +45,7 @@ jobs: - name: setting up database run: | - mysql -h 127.0.0.1 --port 8888 -u root -p123456 < ./api/script/db/schema.sql - - - name: use ci config - run: | - mv ./api/conf/conf-ci.json ./api/conf/conf.json + mysql -h 127.0.0.1 --port 3306 -u root -p123456 < ./api/script/db/schema.sql - name: setup go uses: actions/setup-go@v1 diff --git a/.github/workflows/api_cicd.yml b/.github/workflows/api_cicd.yml index 1344bd9396..a906135262 100644 --- a/.github/workflows/api_cicd.yml +++ b/.github/workflows/api_cicd.yml @@ -30,7 +30,7 @@ jobs: env: MYSQL_ROOT_PASSWORD: 123456 ports: - - '8888:3306' + - '3306:3306' options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 @@ -39,11 +39,7 @@ jobs: - name: setting up database run: | - mysql -h 127.0.0.1 --port 8888 -u root -p123456 < ./api/script/db/schema.sql - - - name: use ci config - run: | - mv ./api/conf/conf-ci.json ./api/conf/conf.json + mysql -h 127.0.0.1 --port 3306 -u root -p123456 < ./api/script/db/schema.sql - name: setup go uses: actions/setup-go@v1 diff --git a/api/conf/conf-ci.json b/api/conf/conf-ci.json deleted file mode 100644 index 78f06fc020..0000000000 --- a/api/conf/conf-ci.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "conf":{ - "mysql":{ - "address": "127.0.0.1:3306", - "user": "root", - "password": "123456", - "maxConns": 50, - "maxIdleConns": 25, - "maxLifeTime": 10 - }, - "syslog":{ - "host": "localhost" - }, - "apisix":{ - "base_url": "http://127.0.0.1:9080/apisix/admin", - "api_key": "edd1c9f034335f136f87ad84b625c8f1" - } - } -}