|
| 1 | +name: Docker Image CI/CD |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + - develop |
| 8 | + - features/* |
| 9 | + pull_request: |
| 10 | + branches: |
| 11 | + - main |
| 12 | + - develop |
| 13 | + release: |
| 14 | + types: [published] |
| 15 | + |
| 16 | +jobs: |
| 17 | + setup_tag: |
| 18 | + name: Setup dockerTag |
| 19 | + runs-on: ubuntu-latest |
| 20 | + outputs: |
| 21 | + docker_tag: ${{ steps.setup_docker_tag.outputs.DockerTag }} |
| 22 | + steps: |
| 23 | + - name: Checkout |
| 24 | + uses: actions/checkout@v3 |
| 25 | + |
| 26 | + - name: Setup dockerTag |
| 27 | + id: setup_docker_tag |
| 28 | + run: | |
| 29 | + if [[ "${{ github.event_name }}" == "pull_request" ]]; then |
| 30 | + case "${{ github.base_ref }}" in |
| 31 | + "develop") |
| 32 | + echo "::set-output name=DockerTag::dev-pr" |
| 33 | + ;; |
| 34 | + "main") |
| 35 | + echo "::set-output name=DockerTag::main-pr" |
| 36 | + ;; |
| 37 | + esac |
| 38 | + else |
| 39 | + case "${{ github.ref }}" in |
| 40 | + refs/heads/features/*) |
| 41 | + echo "::set-output name=DockerTag::alpha" |
| 42 | + ;; |
| 43 | + "refs/heads/develop") |
| 44 | + echo "::set-output name=DockerTag::dev" |
| 45 | + ;; |
| 46 | + "refs/heads/main") |
| 47 | + echo "::set-output name=DockerTag::rc" |
| 48 | + ;; |
| 49 | + "refs/tags/*") |
| 50 | + echo "::set-output name=DockerTag::release" |
| 51 | + ;; |
| 52 | + esac |
| 53 | + fi |
| 54 | +
|
| 55 | + build_app: |
| 56 | + name: install dependencies and build |
| 57 | + runs-on: ubuntu-latest |
| 58 | + |
| 59 | + steps: |
| 60 | + - name: Checkout repo |
| 61 | + uses: actions/checkout@v3 |
| 62 | + |
| 63 | + - name: Install Node.js |
| 64 | + uses: actions/setup-node@v3 |
| 65 | + with: |
| 66 | + node-version: lts/* |
| 67 | + registry-url: https://npm.pkg.github.com/ |
| 68 | + |
| 69 | + - uses: pnpm/action-setup@v2 |
| 70 | + name: Install pnpm |
| 71 | + with: |
| 72 | + version: latest |
| 73 | + run_install: false |
| 74 | + |
| 75 | + - name: Get pnpm store directory |
| 76 | + shell: bash |
| 77 | + run: | |
| 78 | + echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV |
| 79 | +
|
| 80 | + - name: Set NPM Token |
| 81 | + run: echo "//npm.pkg.github.com/:_authToken=${{secrets.GITHUB_TOKEN}}">.npmrc |
| 82 | + |
| 83 | + - uses: actions/cache@v3 |
| 84 | + name: Setup pnpm cache |
| 85 | + with: |
| 86 | + path: ${{ env.STORE_PATH }} |
| 87 | + key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} |
| 88 | + restore-keys: | |
| 89 | + ${{ runner.os }}-pnpm-store- |
| 90 | +
|
| 91 | + - name: Install dependencies |
| 92 | + run: pnpm install |
| 93 | + |
| 94 | + - name: Build project |
| 95 | + run: pnpm build |
| 96 | + |
| 97 | + - name: Archive compiled files |
| 98 | + uses: actions/upload-artifact@v2 |
| 99 | + with: |
| 100 | + name: compiled-files |
| 101 | + path: ./dist/* |
| 102 | + |
| 103 | + CI: |
| 104 | + name: Building and deploy Image from-a2b-map |
| 105 | + runs-on: ubuntu-latest |
| 106 | + needs: |
| 107 | + - setup_tag |
| 108 | + - build_app |
| 109 | + steps: |
| 110 | + - name: Checkout |
| 111 | + uses: actions/checkout@v3 |
| 112 | + |
| 113 | + - name: Download compiled files artifact |
| 114 | + uses: actions/download-artifact@v2 |
| 115 | + with: |
| 116 | + name: compiled-files |
| 117 | + path: ./dist |
| 118 | + |
| 119 | + - name: DockerHub login |
| 120 | + uses: docker/login-action@v1 |
| 121 | + with: |
| 122 | + username: ${{ secrets.DOCKER_USER }} |
| 123 | + password: ${{ secrets.DOCKER_PASSWORD }} |
| 124 | + |
| 125 | + - name: Set up Docker Buildx |
| 126 | + uses: docker/setup-buildx-action@v1 |
| 127 | + |
| 128 | + - name: Build Docker Image |
| 129 | + run: docker buildx build --platform linux/amd64,linux/arm --file ./Dockerfile.Release --tag ${{ secrets.REGISTRY_NAME }}/from-a2b-map:${{ needs.setup_tag.outputs.docker_tag }} --push ./dist |
| 130 | + |
| 131 | + # CD: |
| 132 | + # name: Update Portainer Service |
| 133 | + # runs-on: ubuntu-latest |
| 134 | + # needs: CI |
| 135 | + # if: ${{ needs.CI.result == 'success' }} |
| 136 | + # steps: |
| 137 | + # - name: Send POST request to Portainer webhook |
| 138 | + # run: | |
| 139 | + # case "${{ github.ref }}" in |
| 140 | + # "refs/heads/develop") |
| 141 | + # curl -X POST -H "Content-Type: application/json" -d '{}' ${{ secrets.FROMA2B_PORTAINER_WEBHOOK_API_DEV }} |
| 142 | + # ;; |
| 143 | + # "refs/heads/main") |
| 144 | + # curl -X POST -H "Content-Type: application/json" -d '{}' ${{ secrets.FROMA2B_PORTAINER_WEBHOOK_STAGING }} |
| 145 | + # ;; |
| 146 | + # "refs/tags/*") |
| 147 | + # curl -X POST -H "Content-Type: application/json" -d '{}' ${{ secrets.FROMA2B_PORTAINER_WEBHOOK_API_RELEASE }} |
| 148 | + # ;; |
| 149 | + # esac |
0 commit comments