Skip to content

Commit

Permalink
Merge pull request #71 from yalla-coop/jelastic-spike
Browse files Browse the repository at this point in the history
CI action to build and deploy to jelastic
  • Loading branch information
ajluker authored Jul 30, 2024
2 parents b15e487 + 466d7c7 commit c7b5aaf
Showing 3 changed files with 86 additions and 0 deletions.
67 changes: 67 additions & 0 deletions .github/workflows/build-and-deploy.yml
Original file line number Diff line number Diff line change
@@ -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
18 changes: 18 additions & 0 deletions .github/workflows/deploy-staging.yml
Original file line number Diff line number Diff line change
@@ -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

1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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 .

0 comments on commit c7b5aaf

Please sign in to comment.