|
1 | | -# shared-github-actions |
2 | | -Github-actions worflows and actions accessible to all Pexip workflows |
| 1 | +# Pexip shared github-actions |
3 | 2 |
|
4 | | -## Examples |
| 3 | +GitHub Actions workflows and actions accessible to all Pexip workflows. This repository provides reusable composite actions for common CI/CD tasks including Docker builds, security scanning, Terraform deployments, and release automation. |
| 4 | + |
| 5 | +## Table of Contents |
| 6 | + |
| 7 | +- [Available Actions](#available-actions) |
| 8 | +- [Quick Start](#quick-start) |
| 9 | +- [Prerequisites](#prerequisites) |
| 10 | +- [Examples](#examples) |
| 11 | + |
| 12 | +## Available Actions |
| 13 | + |
| 14 | +### Authentication |
| 15 | + |
| 16 | +- **[auth-gcp-action](auth-gcp-action)** - Authenticate with Google Cloud Platform using service account key or workload identity federation |
| 17 | +- **[auth-github-action](auth-github-action)** - Authenticate with GitHub Container Registry |
| 18 | + |
| 19 | +### Docker |
| 20 | + |
| 21 | +- **[docker-build-action](docker-build-action)** - Build and push Docker images with automatic tagging and metadata |
| 22 | +- **[docker-security-scan-action](docker-security-scan-action)** - Security scan Docker images using Snyk |
| 23 | + |
| 24 | +### Terraform |
| 25 | + |
| 26 | +- **[terraform-deploy-gcp-action](terraform-deploy-gcp-action)** - Deploy infrastructure to GCP using Terraform (init, validate, plan, apply) |
| 27 | +- **[terraform-deploy-openstack-action](terraform-deploy-openstack-action)** - Deploy infrastructure to OpenStack using Terraform |
| 28 | + |
| 29 | +### Release |
| 30 | + |
| 31 | +- **[release-action](release-action)** - Create GitHub releases with auto-generated notes and optional Jira integration |
| 32 | + |
| 33 | +### Security Tools |
| 34 | + |
| 35 | +- **[setup-zizmor-action](setup-zizmor-action)** - Install zizmor CLI tool for GitHub Actions security analysis |
| 36 | + |
| 37 | +## Quick Start |
5 | 38 |
|
6 | | -The examples are located in the '/examples' folder. |
| 39 | +### Using Actions in Your Workflow |
7 | 40 |
|
8 | | -## Automatically generated release notes |
| 41 | +Reference actions from this repository using the following pattern: |
9 | 42 |
|
10 | | -The release workflow automatically generates release notes based on how pull requests are labeled. |
11 | | -The example configuration expects the following labels to be used: |
| 43 | +```yaml |
| 44 | +uses: pexip/shared-github-actions/{action-name}@{ref} |
| 45 | +``` |
| 46 | +
|
| 47 | +### Example: Build and Push Docker Image |
| 48 | +
|
| 49 | +```yaml |
| 50 | +steps: |
| 51 | + - name: Checkout |
| 52 | + uses: actions/checkout@v4 |
| 53 | + |
| 54 | + - uses: pexip/shared-github-actions/auth-gcp-action@master |
| 55 | + with: |
| 56 | + repository: ${{ vars.DOCKER_REPO }} |
| 57 | + service_account_key: ${{ secrets.DEPLOY_SERVICE_ACCOUNT_KEY }} |
12 | 58 |
|
13 | | -* bug |
14 | | -* change |
15 | | -* feature |
| 59 | + - uses: pexip/shared-github-actions/docker-build-action@master |
| 60 | + with: |
| 61 | + repository: ${{ vars.DOCKER_REPO }} |
| 62 | + image_name: my-application |
| 63 | + dockerfile: Dockerfile |
| 64 | +``` |
16 | 65 |
|
17 | | -This is controlled through the '.github/release.yml' configuration file |
| 66 | +### Example: Terraform Deployment |
18 | 67 |
|
19 | 68 | ```yaml |
20 | | -changelog: |
21 | | - categories: |
22 | | - - title: New |
23 | | - labels: |
24 | | - - '*' |
25 | | - exclude: |
26 | | - labels: |
27 | | - - bug |
28 | | - - change |
29 | | - - title: Changes |
30 | | - labels: |
31 | | - - change |
32 | | - - title: Bug Fixes |
33 | | - labels: |
34 | | - - bug |
| 69 | +steps: |
| 70 | + - name: Checkout |
| 71 | + uses: actions/checkout@v4 |
| 72 | + |
| 73 | + - uses: pexip/shared-github-actions/auth-gcp-action@master |
| 74 | + with: |
| 75 | + repository: ${{ vars.DOCKER_REPO }} |
| 76 | + service_account_key: ${{ secrets.DEPLOY_SERVICE_ACCOUNT_KEY }} |
| 77 | + |
| 78 | + - uses: pexip/shared-github-actions/terraform-deploy-gcp-action@master |
| 79 | + with: |
| 80 | + directory: ./deploy |
| 81 | + token: ${{ secrets.GITHUB_TOKEN }} |
35 | 82 | ``` |
36 | 83 |
|
| 84 | +### Example: Authenticate with Workload Identity Federation |
| 85 | +
|
| 86 | +Workload Identity Federation allows GitHub Actions to authenticate to GCP without using service account keys. |
| 87 | +
|
| 88 | +#### Prerequisites |
| 89 | +
|
| 90 | +1. **Create a Workload Identity Pool:** |
| 91 | + ```bash |
| 92 | + gcloud iam workload-identity-pools create "github-pool" \ |
| 93 | + --project="${PROJECT_ID}" \ |
| 94 | + --location="global" \ |
| 95 | + --display-name="GitHub Actions Pool" |
| 96 | + ``` |
| 97 | + |
| 98 | +2. **Create a Workload Identity Provider:** |
| 99 | + ```bash |
| 100 | + gcloud iam workload-identity-pools providers create-oidc "github-provider" \ |
| 101 | + --project="${PROJECT_ID}" \ |
| 102 | + --location="global" \ |
| 103 | + --workload-identity-pool="github-pool" \ |
| 104 | + --display-name="GitHub provider" \ |
| 105 | + --attribute-mapping="google.subject=assertion.sub,attribute.actor=assertion.actor,attribute.repository=assertion.repository,attribute.repository_owner=assertion.repository_owner" \ |
| 106 | + --attribute-condition="assertion.repository_owner == 'pexip'" \ |
| 107 | + --issuer-uri="https://token.actions.githubusercontent.com" |
| 108 | + ``` |
| 109 | + |
| 110 | +3. **Create a Service Account:** |
| 111 | + ```bash |
| 112 | + gcloud iam service-accounts create "github-actions-sa" \ |
| 113 | + --project="${PROJECT_ID}" \ |
| 114 | + --display-name="GitHub Actions Service Account" |
| 115 | + ``` |
| 116 | + |
| 117 | +4. **Grant permissions to the Service Account:** |
| 118 | + ```bash |
| 119 | + # Example: Grant Artifact Registry |
| 120 | + gcloud projects add-iam-policy-binding ${PROJECT_ID} \ |
| 121 | + --member="serviceAccount:github-actions-sa@${PROJECT_ID}.iam.gserviceaccount.com" \ |
| 122 | + --role="roles/artifactregistry.writer" |
| 123 | + ``` |
| 124 | + |
| 125 | +5. **Allow the Workload Identity Pool to impersonate the Service Account:** |
| 126 | + ```bash |
| 127 | + gcloud iam service-accounts add-iam-policy-binding "github-actions-sa@${PROJECT_ID}.iam.gserviceaccount.com" \ |
| 128 | + --project="${PROJECT_ID}" \ |
| 129 | + --role="roles/iam.workloadIdentityUser" \ |
| 130 | + --member="principalSet://iam.googleapis.com/projects/${PROJECT_NUMBER}/locations/global/workloadIdentityPools/github-pool/attribute.repository/pexip/REPOSITORY_NAME" |
| 131 | + ``` |
| 132 | + |
| 133 | +6. **Get the Workload Identity Provider resource name:** |
| 134 | + ```bash |
| 135 | + gcloud iam workload-identity-pools providers describe "github-provider" \ |
| 136 | + --project="${PROJECT_ID}" \ |
| 137 | + --location="global" \ |
| 138 | + --workload-identity-pool="github-pool" \ |
| 139 | + --format="value(name)" |
| 140 | + ``` |
| 141 | + Save this value as `WORKLOAD_IDENTITY_PROVIDER` variable in your repository. |
| 142 | + |
| 143 | +#### Usage |
| 144 | + |
| 145 | +```yaml |
| 146 | +steps: |
| 147 | + - name: Checkout |
| 148 | + uses: actions/checkout@v4 |
| 149 | + |
| 150 | + - uses: pexip/shared-github-actions/auth-gcp-action@master |
| 151 | + with: |
| 152 | + repository: ${{ vars.DOCKER_REPO }} |
| 153 | + workload_identity_provider: ${{ vars.WORKLOAD_IDENTITY_PROVIDER }} |
| 154 | + service_account: ${{ vars.SERVICE_ACCOUNT_EMAIL }} |
| 155 | + |
| 156 | + - uses: pexip/shared-github-actions/docker-build-action@master |
| 157 | + with: |
| 158 | + repository: ${{ vars.DOCKER_REPO }} |
| 159 | + image_name: my-application |
| 160 | + dockerfile: Dockerfile |
| 161 | +``` |
| 162 | +
|
| 163 | +### Example: Create a Release |
| 164 | +
|
| 165 | +```yaml |
| 166 | +steps: |
| 167 | + - name: Checkout |
| 168 | + uses: actions/checkout@v4 |
| 169 | + |
| 170 | + - uses: pexip/shared-github-actions/release-action@master |
| 171 | + with: |
| 172 | + version: v1.0.0 |
| 173 | + github_token: ${{ secrets.GITHUB_TOKEN }} |
| 174 | +``` |
| 175 | +
|
| 176 | +## Prerequisites |
| 177 | +
|
| 178 | +### Required Secrets |
| 179 | +
|
| 180 | +Configure these secrets in your repository settings: |
| 181 | +
|
| 182 | +- **`DEPLOY_SERVICE_ACCOUNT_KEY`** - GCP service account JSON key for authentication and Docker registry access |
| 183 | +- **`SNYK_PEXIP_UNSORTED_ACCESS_TOKEN`** - Snyk API token for security scanning (if using docker-security-scan) |
| 184 | +- **`GITHUB_TOKEN`** - Automatically provided by GitHub Actions |
| 185 | + |
| 186 | +### Optional Secrets |
| 187 | + |
| 188 | +- **`jira_webhook`** - Jira automation webhook URL for release integration |
| 189 | + |
| 190 | +### Required Variables |
| 191 | + |
| 192 | +Configure these variables in your repository settings: |
| 193 | + |
| 194 | +- **`DOCKER_REPO`** - Docker repository URL (e.g., `europe-docker.pkg.dev/project-id/repo-name`) |
| 195 | +- **`DOCKER_IMAGE`** - Docker image name |
| 196 | +- **`DEPLOY_PROJECT_ID`** - GCP project ID for deployments |
| 197 | + |
| 198 | +### Optional Variables (for Workload Identity Federation) |
| 199 | + |
| 200 | +If using Workload Identity Federation instead of service account keys: |
| 201 | + |
| 202 | +- **`WORKLOAD_IDENTITY_PROVIDER`** - Workload identity provider resource name (e.g., `projects/PROJECT_NUMBER/locations/global/workloadIdentityPools/POOL_ID/providers/PROVIDER_ID`) |
| 203 | +- **`SERVICE_ACCOUNT_EMAIL`** - Service account email to impersonate (e.g., `my-service-account@project-id.iam.gserviceaccount.com`) |
| 204 | + |
| 205 | +## Examples |
| 206 | + |
| 207 | +Complete workflow examples are located in the [examples](examples) folder: |
| 208 | + |
| 209 | +- **[development.yml](examples/development.yml)** - Full development pipeline with Docker build, security scan, and Terraform deployment |
| 210 | +- **[production.yml](examples/production.yml)** - Production deployment workflow triggered on main branch pushes or version tags |
| 211 | +- **[release.yml](examples/release.yml)** - Release workflow with GitHub and Jira integration |
37 | 212 |
|
| 213 | +These examples demonstrate common patterns for integrating multiple actions into complete CI/CD pipelines. |
0 commit comments