diff --git a/.github/workflows/build-and-deploy-prod.yml b/.github/workflows/build-and-deploy-prod.yml new file mode 100644 index 0000000..dc7db46 --- /dev/null +++ b/.github/workflows/build-and-deploy-prod.yml @@ -0,0 +1,67 @@ +name: Create and publish a Docker image +on: + workflow_call: + inputs: + jelastic_env: + description: "Jelastic environment name" + required: true + type: string + image_name: + description: "Name for image" + required: false + default: ${{ github.repository }} + type: string + secrets: + jelastic_access_token: + required: true + shopify_api_key: + required: true + +jobs: + build-and-push-image: + runs-on: ubuntu-latest + env: + SHOPIFY_API_KEY: ${{ secrets.shopify_api_key_production }} + steps: + - name: Checkout repository + uses: actions/checkout@v4 + # Uses the `docker/login-action` action to log in to the Container registry registry using the account and password that will publish the packages. Once published, the packages are scoped to the account defined here. + - name: Log in to the Container registry + uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + # This step uses [docker/metadata-action](https://github.com/docker/metadata-action#about) to extract tags and labels that will be applied to the specified image. The `id` "meta" allows the output of this step to be referenced in a subsequent step. The `images` value provides the base name for the tags and labels. + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v5 + with: + tags: | + type=sha,prefix={{branch}}- + + # This step uses the `docker/build-push-action` action to build the image, based on your repository's `Dockerfile`. If the build succeeds, it pushes the image to GitHub Packages. + # It uses the `context` parameter to define the build's context as the set of files located in the specified path. For more information, see "[Usage](https://github.com/docker/build-push-action#usage)" in the README of the `docker/build-push-action` repository. + # It uses the `tags` and `labels` parameters to tag and label the image with the output from the "meta" step. + - name: Build and push Docker image + id: push + uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4 + with: + context: . + push: true + build-args: | + SHOPIFY_API_KEY=${{ secrets.shopify_api_key_production }} + tags: ghcr.io/${{ inputs.image_name }}:${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + + # This step generates an artifact attestation for the image, which is an unforgeable statement about where and how it was built. It increases supply chain security for people who consume the image. For more information, see "[AUTOTITLE](/actions/security-guides/using-artifact-attestations-to-establish-provenance-for-builds)." + # - name: Generate artifact attestation + # uses: actions/attest-build-provenance@v1 + # with: + # subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}} + # subject-digest: ${{ steps.push.outputs.digest }} + # push-to-registry: true + - name: Redeploy containers + run: | + sudo apt-get install curl -y + curl https://app.jpc.infomaniak.com/1.0/environment/control/rest/redeploycontainersbygroup?envName=${{inputs.jelastic_env}}\&session=${{secrets.jelastic_access_token}}\&tag=${{steps.meta.outputs.tags}}\&nodeGroup=cp diff --git a/.github/workflows/deploy-production.yml b/.github/workflows/deploy-production.yml index eead546..e410730 100644 --- a/.github/workflows/deploy-production.yml +++ b/.github/workflows/deploy-production.yml @@ -2,7 +2,7 @@ name: Create and publish a Docker image on: push: - branches: ['main'] + branches: ["main"] jobs: build-and-push-image: @@ -11,8 +11,7 @@ jobs: packages: write attestations: write id-token: write - uses: ./.github/workflows/build-and-deploy.yml + uses: ./.github/workflows/build-and-deploy-prod.yml with: jelastic_env: fdc-hub secrets: inherit - \ No newline at end of file