|
91 | 91 | ``` |
92 | 92 |
|
93 | 93 | This workflow will run everytime you push or merge something in the main branch of your repository. You can find the URL of the deployed website in `Settings > Pages` in your GitHub repository. |
| 94 | + |
| 95 | + |
| 96 | +## Deploy With GitHub Actions to Cloudflare |
| 97 | + |
| 98 | +To deploy to [Cloudflare Pages](https://pages.cloudflare.com/), you will need to have a [Cloudflare](https://www.cloudflare.com/) account. First you will need to retrieve your account ID from Cloudflare, the documentation on how to retrieve it is available on the [Cloudflare documentation](https://developers.cloudflare.com/fundamentals/account/find-account-and-zone-ids/) |
| 99 | + |
| 100 | +Then, you will need to create a new API token from your [Cloudflare Profile page](https://dash.cloudflare.com/profile/api-tokens): |
| 101 | +- First click on `Create Token` |
| 102 | +- Then on the `Edit Cloudflare Workers` template |
| 103 | +- Select your organization inside the `Account Resources` |
| 104 | +- Select `All Zones` for `Zone Resources` |
| 105 | +- Then `Continue to Summary` |
| 106 | +- Then `Create Token`. |
| 107 | + |
| 108 | +More information on how to create an API token is available on the [Cloudflare documentation](https://developers.cloudflare.com/fundamentals/api/get-started/create-token/). |
| 109 | + |
| 110 | +To create a new Cloudflare Page App, go to your Cloudflare dashboard, then on `Compute (workers) > Workers & Pages > Create > Pages tab`. Create a new pages from direct upload, enter your project name and then click on `Create Project`, then go back to the `Compute page`. |
| 111 | + |
| 112 | + |
| 113 | + |
| 114 | +Once you have configured your API token and retrieved your Account ID, you can setup the following secrets in your repository by going to `Settings > Secrets and variables > Actions` on your GitHub repository: |
| 115 | + |
| 116 | + |
| 117 | +```sh |
| 118 | +# Your Cloudlfare API token |
| 119 | +CLOUDFLARE_API_TOKEN= |
| 120 | +
|
| 121 | +# Your Cloudlfare Account ID |
| 122 | +CLOUDFLARE_ACCOUNT_ID= |
| 123 | +
|
| 124 | +# The Cloudflare Pages |
| 125 | +CLOUDFLARE_PROJECT_NAME= |
| 126 | +``` |
| 127 | + |
| 128 | +Once your project has been configured, initialize a new workflow in your repository `.github/workflows/admin.yml` with the following content: |
| 129 | +```yml |
| 130 | +name: Build and deploy React-admin |
| 131 | +
|
| 132 | +on: |
| 133 | + push: |
| 134 | + branches: |
| 135 | + - main |
| 136 | +
|
| 137 | +jobs: |
| 138 | + build: |
| 139 | + name: Build the admin panel to be deployed |
| 140 | + runs-on: ubuntu-latest |
| 141 | + steps: |
| 142 | + - uses: actions/checkout@v4 |
| 143 | +
|
| 144 | + - uses: actions/setup-node@v4 |
| 145 | + with: |
| 146 | + node-version: lts/* |
| 147 | +
|
| 148 | + - name: Install dependencies |
| 149 | + run: npm install |
| 150 | +
|
| 151 | + - name: Build |
| 152 | + run: npm run build |
| 153 | +
|
| 154 | + - name: Upload dist folder as an artifact |
| 155 | + uses: actions/upload-artifact@v4 |
| 156 | + with: |
| 157 | + name: dist |
| 158 | + path: dist |
| 159 | +
|
| 160 | + deploy: |
| 161 | + name: Deploy React-admin Application to Cloudflare |
| 162 | + runs-on: ubuntu-latest |
| 163 | + needs: build |
| 164 | +
|
| 165 | + permissions: |
| 166 | + contents: read |
| 167 | + deployments: write |
| 168 | +
|
| 169 | + steps: |
| 170 | + - name: Download prebuilt admin |
| 171 | + uses: actions/download-artifact@v4 |
| 172 | + with: |
| 173 | + name: dist |
| 174 | + path: dist |
| 175 | +
|
| 176 | + - name: Display structure of downloaded files |
| 177 | + run: ls -R |
| 178 | +
|
| 179 | + - name: Deploy artifact to Cloudflare |
| 180 | + uses: cloudflare/wrangler-action@v3 |
| 181 | + with: |
| 182 | + apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} |
| 183 | + accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} |
| 184 | + command: pages deploy dist --project-name=${{ secrets.CLOUDFLARE_PROJECT_NAME }} |
| 185 | + gitHubToken: ${{ secrets.GITHUB_TOKEN }} |
| 186 | +``` |
| 187 | + |
| 188 | +Now, each time your code will be pushed to your main branch, an action will be started that will automatically deploy your app to your Cloudflare Pages app. |
0 commit comments