Devcontainer setup and initial image build pipeline #1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: OSTicket CI/CD Pipeline | |
| on: | |
| push: | |
| branches: | |
| - develop | |
| - release/* | |
| - feature/* | |
| pull_request: | |
| branches: [ develop ] | |
| env: | |
| REGISTRY: ghcr.io | |
| IMAGE_NAME: ${{ github.repository }} | |
| jobs: | |
| build-and-test: | |
| name: Build and Test | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| packages: write | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Log in to Container registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ${{ env.REGISTRY }} | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Extract metadata for Docker | |
| id: meta | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | |
| tags: | | |
| type=semver,pattern={{version}} | |
| type=semver,pattern={{major}}.{{minor}} | |
| type=sha,format=long | |
| type=ref,event=branch | |
| - name: Set up QEMU | |
| uses: docker/setup-qemu-action@v3 | |
| with: | |
| platforms: 'arm64,amd64' | |
| - name: Build and push PHP-FPM Docker image | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: . | |
| file: ./docker/Dockerfile | |
| push: ${{ github.event_name != 'pull_request' }} | |
| tags: ${{ steps.meta.outputs.tags }} | |
| labels: ${{ steps.meta.outputs.labels }} | |
| target: production | |
| platforms: linux/amd64,linux/arm64 | |
| cache-from: type=gha,scope=build-php | |
| cache-to: type=gha,scope=build-php,mode=max | |
| build-args: | | |
| VERSION=${{ github.sha }} | |
| - name: Build and push Nginx Docker image | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: . | |
| file: ./docker/Dockerfile | |
| push: ${{ github.event_name != 'pull_request' }} | |
| tags: ${{ steps.meta.outputs.tags }}-nginx | |
| labels: ${{ steps.meta.outputs.labels }} | |
| target: nginx | |
| platforms: linux/amd64,linux/arm64 | |
| cache-from: type=gha,scope=build-nginx | |
| cache-to: type=gha,scope=build-nginx,mode=max | |
| build-args: | | |
| VERSION=${{ github.sha }} | |
| - name: Run Trivy vulnerability scanner | |
| uses: aquasecurity/trivy-action@v1 | |
| with: | |
| image-ref: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.sha }} | |
| format: 'sarif' | |
| output: 'trivy-results.sarif' | |
| - name: Upload Trivy scan results | |
| uses: github/codeql-action/upload-sarif@v3 | |
| if: always() | |
| with: | |
| sarif_file: 'trivy-results.sarif' | |
| deploy-staging: | |
| name: Deploy to Staging | |
| if: github.event_name != 'pull_request' && github.ref == 'refs/heads/main' | |
| needs: build-and-test | |
| runs-on: ubuntu-latest | |
| environment: staging | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up Kubernetes toolset | |
| uses: azure/setup-kubectl@v4 | |
| - name: Set up Kustomize | |
| uses: imranismail/setup-kustomize@v2 | |
| with: | |
| kustomize-version: "4.5.7" | |
| - name: Configure Kubernetes context | |
| uses: azure/k8s-set-context@v4 | |
| with: | |
| kubeconfig: ${{ secrets.KUBE_CONFIG }} | |
| - name: Update Kustomization | |
| run: | | |
| cd kubernetes | |
| kustomize edit set image "${REGISTRY}/${IMAGE_NAME}=${REGISTRY}/${IMAGE_NAME}:${GITHUB_SHA}" | |
| - name: Deploy to Staging | |
| run: | | |
| cd kubernetes | |
| kubectl apply -k . --namespace=staging | |
| kubectl rollout status deployment/php-fpm --namespace=staging | |
| kubectl rollout status deployment/nginx --namespace=staging | |
| deploy-production: | |
| name: Deploy to Production | |
| if: startsWith(github.ref, 'refs/heads/release/') | |
| needs: build-and-test | |
| runs-on: ubuntu-latest | |
| environment: production | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up Kubernetes toolset | |
| uses: azure/setup-kubectl@v4 | |
| - name: Set up Kustomize | |
| uses: imranismail/setup-kustomize@v2 | |
| with: | |
| kustomize-version: "4.5.7" | |
| - name: Configure Kubernetes context | |
| uses: azure/k8s-set-context@v4 | |
| with: | |
| kubeconfig: ${{ secrets.KUBE_CONFIG }} | |
| - name: Update Kustomization | |
| run: | | |
| cd kubernetes | |
| kustomize edit set image "${REGISTRY}/${IMAGE_NAME}=${REGISTRY}/${IMAGE_NAME}:${GITHUB_SHA}" | |
| - name: Deploy to Production | |
| run: | | |
| cd kubernetes | |
| kubectl apply -k . --namespace=production | |
| kubectl rollout status deployment/php-fpm --namespace=production | |
| kubectl rollout status deployment/nginx --namespace=production |