|
| 1 | +--- |
| 2 | +title: CircleCI Arm64 Cloud-Native Demo |
| 3 | +weight: 8 |
| 4 | + |
| 5 | +### FIXED, DO NOT MODIFY |
| 6 | +layout: learningpathall |
| 7 | +--- |
| 8 | + |
| 9 | +## Deploying a Cloud-Native Arm64 Node.js App using self-hosted CircleCI Runner on GCP |
| 10 | + |
| 11 | +This guide walks through building and testing a simple **Node.js web app** using a **self-hosted CircleCI Arm64 runner** on a **GCP SUSE Arm64 VM**. |
| 12 | + |
| 13 | + |
| 14 | +### Install and Configure Docker |
| 15 | +Ensure Docker is installed, started, and accessible by both your user and the CircleCI runner service. |
| 16 | + |
| 17 | +- **Install Docker**: Refresh your package manager and install Docker on your system. |
| 18 | +- **Enable Docker Service**: Ensure Docker starts on boot and is running. |
| 19 | +- **Add User to Docker Group**: Add both your user and the CircleCI runner to the Docker group to grant access. |
| 20 | + |
| 21 | +```console |
| 22 | +sudo zypper refresh |
| 23 | +sudo zypper install docker |
| 24 | +sudo systemctl enable docker |
| 25 | +sudo systemctl start docker |
| 26 | +sudo systemctl status docker |
| 27 | +sudo usermod -aG docker $USER |
| 28 | +sudo usermod -aG docker circleci |
| 29 | +``` |
| 30 | +### Validate Docker access |
| 31 | +This command switches to the CircleCI user and checks if Docker is working correctly. |
| 32 | + |
| 33 | +```console |
| 34 | +sudo -u circleci -i |
| 35 | +docker ps |
| 36 | +exit |
| 37 | +``` |
| 38 | + |
| 39 | +### Verify Docker Permissions |
| 40 | +Check Docker socket permissions and ensure that the CircleCI runner is active and running. |
| 41 | + |
| 42 | +```console |
| 43 | +ls -l /var/run/docker.sock |
| 44 | +ps -aux | grep circleci-runner |
| 45 | +``` |
| 46 | +- **Check Docker Socket Permissions**: This command ensures the Docker socket is accessible. |
| 47 | +- **Verify CircleCI Runner Process**: Confirm the CircleCI runner service is active and running. |
| 48 | + |
| 49 | +### **Install Node.js and npm** |
| 50 | + |
| 51 | +Before proceeding with the app setup, please make sure **Node.js** and **npm** (Node.js package manager) are installed on the VM, as they are required to run your Node.js app. |
| 52 | + |
| 53 | +- **Install Node.js**: Use the official Node.js package for Arm64 architecture. |
| 54 | +- **Install npm**: npm is automatically installed when Node.js is installed. |
| 55 | + |
| 56 | +```console |
| 57 | +sudo zypper install nodejs |
| 58 | +sudo zypper install npm |
| 59 | +``` |
| 60 | +### Clone Your App Repository |
| 61 | +Clone your application repository (or create one locally): |
| 62 | + |
| 63 | +```console |
| 64 | +git clone https://github.com/<your-repo>/arm64-node-demo.git |
| 65 | +cd arm64-node-demo |
| 66 | +``` |
| 67 | + |
| 68 | +### Create a Dockerfile |
| 69 | +In the root of your project, create a `Dockerfile` that defines how to build and run your application container. |
| 70 | + |
| 71 | +```dockerfile |
| 72 | +# Dockerfile |
| 73 | +FROM arm64v8/node:20-alpine |
| 74 | +WORKDIR /app |
| 75 | +COPY package*.json ./ |
| 76 | +RUN npm install |
| 77 | +COPY . . |
| 78 | +EXPOSE 3000 |
| 79 | +CMD ["npm", "start"] |
| 80 | +``` |
| 81 | +- **Use Arm64 Node.js Image**: The `arm64v8/node` image is specifically designed for Arm64 architecture. |
| 82 | +- **Install Dependencies**: `RUN npm install` installs the project dependencies listed in `package.json`. |
| 83 | +- **Expose Port**: The app will run on port 3000. |
| 84 | +- **Start the App**: The container will execute `npm start` to launch the Node.js server. |
| 85 | + |
| 86 | +### Add a CircleCI Configuration |
| 87 | +Create a `.circleci/config.yml` file to define the CircleCI pipeline for building and testing your Node.js app on Arm64 architecture. |
| 88 | + |
| 89 | +```yaml |
| 90 | +version: 2.1 |
| 91 | + |
| 92 | +jobs: |
| 93 | + arm64-demo: |
| 94 | + machine: true |
| 95 | + resource_class: <Your_resource_class> |
| 96 | + steps: |
| 97 | + - checkout |
| 98 | + - run: |
| 99 | + name: Show Architecture |
| 100 | + command: | |
| 101 | + ARCH=$(uname -m) |
| 102 | + echo "Detected architecture: $ARCH" |
| 103 | + if [ "$ARCH" = "aarch64" ]; then |
| 104 | + echo "✅ Running on ARM64 architecture!" |
| 105 | + else |
| 106 | + echo "Not running on ARM64!" |
| 107 | + exit 1 |
| 108 | + fi |
| 109 | + - run: |
| 110 | + name: Build Docker Image |
| 111 | + command: docker build -t arm64-node-demo . |
| 112 | + - run: |
| 113 | + name: Run Docker Container |
| 114 | + command: docker run -d -p 3000:3000 arm64-node-demo |
| 115 | + - run: |
| 116 | + name: Test Endpoint |
| 117 | + command: | |
| 118 | + sleep 5 |
| 119 | + curl http://localhost:3000 |
| 120 | +
|
| 121 | +workflows: |
| 122 | + version: 2 |
| 123 | + arm64-workflow: |
| 124 | + jobs: |
| 125 | + - arm64-demo |
| 126 | +``` |
| 127 | +- **arm64-demo Job**: This job checks if the architecture is Arm64, builds the Docker image, runs it in a container, and tests the app endpoint. |
| 128 | +- **resource_class**: Specify the resource class for the CircleCI runner (e.g., a custom Arm64 runner if using self-hosted). |
| 129 | +- **Test Endpoint**: The job sends a request to the app to verify it’s working. |
| 130 | +
|
| 131 | +### Node.js Application |
| 132 | +Here’s the basic code for the Node.js app. |
| 133 | +
|
| 134 | +`index.js`: |
| 135 | + |
| 136 | +```javascript |
| 137 | +const express = require('express'); |
| 138 | +const app = express(); |
| 139 | +const PORT = process.env.PORT || 3000; |
| 140 | +
|
| 141 | +app.get('/', (req, res) => { |
| 142 | + res.send('Hello from ARM64 Node.js app! 🚀'); |
| 143 | +}); |
| 144 | +
|
| 145 | +app.listen(PORT, () => { |
| 146 | + console.log(`Server running on port ${PORT}`); |
| 147 | +}); |
| 148 | +``` |
| 149 | +package.json |
| 150 | + |
| 151 | +```json |
| 152 | +{ |
| 153 | + "name": "arm64-node-demo", |
| 154 | + "version": "1.0.0", |
| 155 | + "main": "index.js", |
| 156 | + "scripts": { |
| 157 | + "start": "node index.js", |
| 158 | + "test": "echo \"No tests yet\"" |
| 159 | + }, |
| 160 | + "dependencies": { |
| 161 | + "express": "^4.18.2" |
| 162 | + } |
| 163 | +} |
| 164 | +``` |
| 165 | +- **Express Server**: The application uses Express.js to handle HTTP requests and respond with a simple message. |
| 166 | +- **Package Dependencies**: The app requires the `express` package for handling HTTP requests. |
| 167 | + |
| 168 | +### Push Code to GitHub |
| 169 | + |
| 170 | +Once all files (`Dockerfile`, `index.js`, `package.json`, `.circleci/config.yml`) are ready, push your project to GitHub so CircleCI can build it automatically. |
| 171 | + |
| 172 | +```console |
| 173 | +git add . |
| 174 | +git commit -m "Add ARM64 CircleCI Node.js demo project" |
| 175 | +git push -u origin main |
| 176 | +``` |
| 177 | +- **Add and Commit Changes**: Stage and commit your project files. |
| 178 | +- **Push to GitHub**: Push your code to the GitHub repository so that CircleCI can trigger the build. |
| 179 | + |
| 180 | +### Start CircleCI Runner and Execute Job |
| 181 | +Ensure that your CircleCI runner is enabled and started. This will allow your self-hosted runner to pick up jobs from CircleCI. |
| 182 | + |
| 183 | +```console |
| 184 | +sudo systemctl enable circleci-runner |
| 185 | +sudo systemctl start circleci-runner |
| 186 | +sudo systemctl status circleci-runner |
| 187 | +``` |
| 188 | +- **Enable CircleCI Runner**: Ensure the CircleCI runner is set to start automatically on boot. |
| 189 | +- **Start and Check Status**: Start the CircleCI runner and verify it is running. |
| 190 | + |
| 191 | +After pushing your code to GitHub, open your **CircleCI Dashboard → Projects**, and confirm that your **ARM64 workflow** starts running using your **self-hosted runner**. |
| 192 | + |
| 193 | +If the setup is correct, you’ll see your job running under the resource class you created. |
| 194 | + |
| 195 | +### Output |
| 196 | +Once the job starts running, CircleCI will: |
| 197 | + |
| 198 | +- Detect the ARM64 architecture. |
| 199 | + |
| 200 | + |
| 201 | + |
| 202 | +- Build the Docker image. |
| 203 | + |
| 204 | + |
| 205 | + |
| 206 | +- Runs a container from that image. |
| 207 | + |
| 208 | + |
| 209 | + |
| 210 | +- Test the application by hitting the endpoint. |
| 211 | + |
| 212 | + |
| 213 | + |
| 214 | +If successful, you will see your CircleCI job running and the app deployed in the CircleCI Dashboard. |
0 commit comments