From 2c4960c249fd030b778495811e8689105c897789 Mon Sep 17 00:00:00 2001 From: Srdjan S Date: Tue, 17 Dec 2024 11:25:42 +0100 Subject: [PATCH 1/6] Add cloudflare account id to deployment --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e1d5398..629d7f5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -27,6 +27,7 @@ jobs: uses: cloudflare/wrangler-action@v3 with: apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} + accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} preCommands: | cp wrangler.toml.example wrangler.toml envsubst < wrangler.toml.example > wrangler.toml From 265c46f6708f89a6d92cd4d5c4e1506270a3f6f1 Mon Sep 17 00:00:00 2001 From: Srdjan S Date: Tue, 17 Dec 2024 12:33:10 +0100 Subject: [PATCH 2/6] Temporarily enable deployment from dev branch --- .github/workflows/ci.yml | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 629d7f5..cc8d0e9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,12 +13,12 @@ jobs: - run: cp wrangler.toml.example wrangler.toml - uses: actions/setup-node@v4 with: - node-version: 20 + node-version: 22 - run: npm ci - run: npm test deploy: - if: github.ref == 'refs/heads/main' + # TODO: Renable if: github.ref == 'refs/heads/main' needs: [test] runs-on: ubuntu-latest steps: diff --git a/package.json b/package.json index 34edb4e..0a19852 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "description": "A template for kick starting a Cloudflare Workers project", "main": "index.js", "scripts": { - "deploy": "wrangler deploy", + "deploy": "wrangler deploy --env dev", "deploy:prod": "wrangler deploy --env production", "dev": "wrangler dev --env dev", "start": "wrangler dev", From 070cd352471d8be048853a6f76b8ef9dfe069306 Mon Sep 17 00:00:00 2001 From: Srdjan S Date: Tue, 17 Dec 2024 12:35:39 +0100 Subject: [PATCH 3/6] Pull env vars from secrets --- .github/workflows/ci.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cc8d0e9..02f5ffc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -37,7 +37,7 @@ jobs: secrets: | INFLUX_TOKEN env: - INFLUX_METRIC_NAME: ${{ env.INFLUX_METRIC }} - INFLUX_URL: ${{ env.INFLUX_URL }} + INFLUX_METRIC_NAME: ${{ secrets.INFLUX_METRIC }} + INFLUX_URL: ${{ secrets.INFLUX_URL }} INFLUX_TOKEN: ${{ secrets.INFLUX_TOKEN }} - INFLUX_DATABASE: ${{ env.INFLUX_DATABASE }} + INFLUX_DATABASE: ${{ secrets.INFLUX_DATABASE }} From 41facb4052a1c8cc2504d1686917fd68b8e6d27d Mon Sep 17 00:00:00 2001 From: Srdjan S Date: Tue, 17 Dec 2024 12:39:31 +0100 Subject: [PATCH 4/6] Pull env vars from vars context --- .github/workflows/ci.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 02f5ffc..aa33da8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -37,7 +37,7 @@ jobs: secrets: | INFLUX_TOKEN env: - INFLUX_METRIC_NAME: ${{ secrets.INFLUX_METRIC }} - INFLUX_URL: ${{ secrets.INFLUX_URL }} + INFLUX_METRIC_NAME: ${{ vars.INFLUX_METRIC_NAME }} + INFLUX_URL: ${{ vars.INFLUX_URL }} INFLUX_TOKEN: ${{ secrets.INFLUX_TOKEN }} - INFLUX_DATABASE: ${{ secrets.INFLUX_DATABASE }} + INFLUX_DATABASE: ${{ vars.INFLUX_DATABASE }} From 99392737486fd846c2ffc9422c2e9c5bc0daedcd Mon Sep 17 00:00:00 2001 From: Srdjan S Date: Tue, 17 Dec 2024 12:43:09 +0100 Subject: [PATCH 5/6] Enable deployment only for main branch --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index aa33da8..8d65c28 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,7 +18,7 @@ jobs: - run: npm test deploy: - # TODO: Renable if: github.ref == 'refs/heads/main' + if: github.ref == 'refs/heads/main' needs: [test] runs-on: ubuntu-latest steps: From e3fcee0003adc3caed8bea98293997164e526a61 Mon Sep 17 00:00:00 2001 From: Srdjan S Date: Tue, 17 Dec 2024 15:34:12 +0100 Subject: [PATCH 6/6] Update npm scripts --- README.md | 6 ++++-- package.json | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 759a9d6..9eee379 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ cp wrangler.toml.example wrangler.toml npm run dev ``` -## Deployment to production +## Deployment (Github Actions) In order to deploy your worker via Github Actions, you need to have a [Cloudflare API token](https://developers.cloudflare.com/fundamentals/api/get-started/create-token/) and running instance of InfluxDB. @@ -34,4 +34,6 @@ Add generated API token to Github secrets as `CLOUDFLARE_API_TOKEN` and authenti Other required environment variables include the following: - `INFLUX_URL` - InfluxDB URL - `INFLUX_DATABASE` - InfluxDB database (bucket) name -- `INFLUX_METRIC_NAME` - InfluxDB metric name \ No newline at end of file +- `INFLUX_METRIC_NAME` - InfluxDB metric name + +After setting up secrets, you can push your code to Github and worker will be deployed to production environment automatically. diff --git a/package.json b/package.json index 0a19852..8ff8c8c 100644 --- a/package.json +++ b/package.json @@ -5,8 +5,8 @@ "description": "A template for kick starting a Cloudflare Workers project", "main": "index.js", "scripts": { - "deploy": "wrangler deploy --env dev", - "deploy:prod": "wrangler deploy --env production", + "deploy": "wrangler deploy --env production", + "deploy:dev": "wrangler deploy --env dev", "dev": "wrangler dev --env dev", "start": "wrangler dev", "test": "vitest run",