diff --git a/.github/workflows/build-and-deploy.yml b/.github/workflows/build-and-deploy.yml new file mode 100644 index 0000000..2166d16 --- /dev/null +++ b/.github/workflows/build-and-deploy.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 }} + 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 }} + 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 \ No newline at end of file diff --git a/.github/workflows/deploy-staging.yml b/.github/workflows/deploy-staging.yml new file mode 100644 index 0000000..b4ae326 --- /dev/null +++ b/.github/workflows/deploy-staging.yml @@ -0,0 +1,18 @@ +name: Create and publish a Docker image + +on: + push: + branches: ['staging'] + +jobs: + build-and-push-image: + permissions: + contents: read + packages: write + attestations: write + id-token: write + uses: ./.github/workflows/build-and-deploy.yml + with: + jelastic_env: env-9448736 + secrets: inherit + \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 4a5c6b8..66d7b71 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,6 +2,7 @@ FROM node:18-alpine ARG SHOPIFY_API_KEY ENV SHOPIFY_API_KEY=$SHOPIFY_API_KEY + EXPOSE 8081 WORKDIR /app COPY web . diff --git a/web/frontend/pages/SalesSession.jsx b/web/frontend/pages/SalesSession.jsx index 2d19555..b3a5a53 100644 --- a/web/frontend/pages/SalesSession.jsx +++ b/web/frontend/pages/SalesSession.jsx @@ -90,22 +90,6 @@ export default function SalesSession() { }, }); - const { - mutateAsync: editCurrentSalesSession, - isLoading: editCurrentSalesSessionIsLoading, - error: editCurrentSalesSessionError, - } = useAppMutation({ - reactQueryOptions: { - onSuccess: async () => { - await queryClient.invalidateQueries("/api/sales-session"); - setShowSuccessAlert({ - show: true, - type: "updated", - }); - }, - }, - }); - const { mutateAsync: completeCurrentSalesSession, isLoading: completeCurrentSalesSessionIsLoading, @@ -134,22 +118,6 @@ export default function SalesSession() { }, }); - const handleOnEditCurrentSalesSessionClick = async () => { - await editCurrentSalesSession({ - url: "/api/sales-session/current", - fetchInit: { - method: "PATCH", - headers: { - "Content-Type": "application/json", - }, - body: JSON.stringify({ - startDate: startDate.toISOString(), - sessionDurationInDays: Number(sessionDurationInDays), - }), - }, - }); - }; - const handleOnFinishCurrentSalesSessionClick = async () => { await completeCurrentSalesSession({ url: "/api/sales-session/current/complete", @@ -314,20 +282,6 @@ export default function SalesSession() { {createSalesSessionIsLoading ? "Loading..." : "Create Sales Session"} - -