Adding cron deploy to cicd

This commit is contained in:
Yanis JEDRZEJCZAK 2024-04-05 11:43:39 +02:00
parent a71fddc1db
commit 420c24bc0a
3 changed files with 132 additions and 15 deletions

View File

@ -12,7 +12,7 @@ env:
CONTAINER_NAME: back
jobs:
build-and-push-image:
build-and-push-images:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
@ -32,12 +32,16 @@ jobs:
username: nologin
password: ${{ secrets.SCW_SECRET_KEY }}
registry: ${{ env.CONTAINER_REGISTRY_ENDPOINT }}
- name: Build the Docker Image
- name: Build the Back Image
run: docker build . -t ${{ env.CONTAINER_REGISTRY_ENDPOINT }}/${{ env.IMAGE_NAME }}
- name: Push the Docker Image to Scaleway Container Registry
- name: Push the Back Image to Scaleway Container Registry
run: docker push ${{ env.CONTAINER_REGISTRY_ENDPOINT }}/${{ env.IMAGE_NAME }}
deploy-to-scaleway:
needs: build-and-push-image
- name: Build the Cron Image
run: docker build -f Dockerfile-Cron . -t ${{ env.CONTAINER_REGISTRY_ENDPOINT }}/cron
- name: Push the Cron Image to Scaleway Container Registry
run: docker push ${{ env.CONTAINER_REGISTRY_ENDPOINT }}/cron
deploy-back:
needs: build-and-push-images
runs-on: ubuntu-latest
environment: preprod
steps:
@ -71,3 +75,38 @@ jobs:
SCW_SECRET_KEY: ${{ secrets.SCW_SECRET_KEY }}
SCW_DEFAULT_PROJECT_ID: ${{ env.PROJECT_ID }}
SCW_DEFAULT_ORGANIZATION_ID: ${{ secrets.SCW_ORGANIZATION_ID }}
deploy-cron:
needs: build-and-push-images
runs-on: ubuntu-latest
environment: preprod
steps:
- name: Install CLI
uses: scaleway/action-scw@v0
- name: Get container ID
run: |
echo "CONTAINER_ID=$(scw container container list namespace-id=${{env.NAMESPACE_ID}} -o json | jq -r '.[] | select(.name == "cron") | .id')" >> $GITHUB_ENV
env:
SCW_ACCESS_KEY: ${{ secrets.SCW_ACCESS_KEY }}
SCW_SECRET_KEY: ${{ secrets.SCW_SECRET_KEY }}
SCW_DEFAULT_PROJECT_ID: ${{ env.PROJECT_ID }}
SCW_DEFAULT_ORGANIZATION_ID: ${{ secrets.SCW_ORGANIZATION_ID }}
- name: Deploy the container based on the new image
run: |
env_string=""
while IFS= read -r line; do
if [[ "$line" == *"="* ]]; then
key=$(echo "$line" | cut -d '=' -f 1)
value=$(echo "$line" | cut -d '=' -f 2-)
if [[ -n "$key" ]]; then
env_string+="environment-variables.$key=$value "
fi
fi
done <<< "$ENV_VARS"
env_string=$(echo $env_string | sed 's/ $//')
scw container container update ${{ env.CONTAINER_ID }} $env_string
env:
ENV_VARS: ${{ secrets.ENV }}
SCW_ACCESS_KEY: ${{ secrets.SCW_ACCESS_KEY }}
SCW_SECRET_KEY: ${{ secrets.SCW_SECRET_KEY }}
SCW_DEFAULT_PROJECT_ID: ${{ env.PROJECT_ID }}
SCW_DEFAULT_ORGANIZATION_ID: ${{ secrets.SCW_ORGANIZATION_ID }}

View File

@ -12,7 +12,7 @@ env:
CONTAINER_NAME: back
jobs:
build-and-push-image:
build-and-push-images:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
@ -32,12 +32,16 @@ jobs:
username: nologin
password: ${{ secrets.SCW_SECRET_KEY }}
registry: ${{ env.CONTAINER_REGISTRY_ENDPOINT }}
- name: Build the Docker Image
- name: Build the Back Image
run: docker build . -t ${{ env.CONTAINER_REGISTRY_ENDPOINT }}/${{ env.IMAGE_NAME }}
- name: Push the Docker Image to Scaleway Container Registry
- name: Push the Back Image to Scaleway Container Registry
run: docker push ${{ env.CONTAINER_REGISTRY_ENDPOINT }}/${{ env.IMAGE_NAME }}
deploy-to-scaleway:
needs: build-and-push-image
- name: Build the Cron Image
run: docker build -f Dockerfile-Cron . -t ${{ env.CONTAINER_REGISTRY_ENDPOINT }}/cron
- name: Push the Cron Image to Scaleway Container Registry
run: docker push ${{ env.CONTAINER_REGISTRY_ENDPOINT }}/cron
deploy-back:
needs: build-and-push-images
runs-on: ubuntu-latest
environment: prod
steps:
@ -71,3 +75,38 @@ jobs:
SCW_SECRET_KEY: ${{ secrets.SCW_SECRET_KEY }}
SCW_DEFAULT_PROJECT_ID: ${{ env.PROJECT_ID }}
SCW_DEFAULT_ORGANIZATION_ID: ${{ secrets.SCW_ORGANIZATION_ID }}
deploy-cron:
needs: build-and-push-images
runs-on: ubuntu-latest
environment: prod
steps:
- name: Install CLI
uses: scaleway/action-scw@v0
- name: Get container ID
run: |
echo "CONTAINER_ID=$(scw container container list namespace-id=${{env.NAMESPACE_ID}} -o json | jq -r '.[] | select(.name == "cron") | .id')" >> $GITHUB_ENV
env:
SCW_ACCESS_KEY: ${{ secrets.SCW_ACCESS_KEY }}
SCW_SECRET_KEY: ${{ secrets.SCW_SECRET_KEY }}
SCW_DEFAULT_PROJECT_ID: ${{ env.PROJECT_ID }}
SCW_DEFAULT_ORGANIZATION_ID: ${{ secrets.SCW_ORGANIZATION_ID }}
- name: Deploy the container based on the new image
run: |
env_string=""
while IFS= read -r line; do
if [[ "$line" == *"="* ]]; then
key=$(echo "$line" | cut -d '=' -f 1)
value=$(echo "$line" | cut -d '=' -f 2-)
if [[ -n "$key" ]]; then
env_string+="environment-variables.$key=$value "
fi
fi
done <<< "$ENV_VARS"
env_string=$(echo $env_string | sed 's/ $//')
scw container container update ${{ env.CONTAINER_ID }} $env_string
env:
ENV_VARS: ${{ secrets.ENV }}
SCW_ACCESS_KEY: ${{ secrets.SCW_ACCESS_KEY }}
SCW_SECRET_KEY: ${{ secrets.SCW_SECRET_KEY }}
SCW_DEFAULT_PROJECT_ID: ${{ env.PROJECT_ID }}
SCW_DEFAULT_ORGANIZATION_ID: ${{ secrets.SCW_ORGANIZATION_ID }}

View File

@ -12,7 +12,7 @@ env:
CONTAINER_NAME: back
jobs:
build-and-push-image:
build-and-push-images:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
@ -32,12 +32,16 @@ jobs:
username: nologin
password: ${{ secrets.SCW_SECRET_KEY }}
registry: ${{ env.CONTAINER_REGISTRY_ENDPOINT }}
- name: Build the Docker Image
- name: Build the Back Image
run: docker build . -t ${{ env.CONTAINER_REGISTRY_ENDPOINT }}/${{ env.IMAGE_NAME }}
- name: Push the Docker Image to Scaleway Container Registry
- name: Push the Back Image to Scaleway Container Registry
run: docker push ${{ env.CONTAINER_REGISTRY_ENDPOINT }}/${{ env.IMAGE_NAME }}
deploy-to-scaleway:
needs: build-and-push-image
- name: Build the Cron Image
run: docker build -f Dockerfile-Cron . -t ${{ env.CONTAINER_REGISTRY_ENDPOINT }}/cron
- name: Push the Cron Image to Scaleway Container Registry
run: docker push ${{ env.CONTAINER_REGISTRY_ENDPOINT }}/cron
deploy-back:
needs: build-and-push-images
runs-on: ubuntu-latest
environment: staging
steps:
@ -71,3 +75,38 @@ jobs:
SCW_SECRET_KEY: ${{ secrets.SCW_SECRET_KEY }}
SCW_DEFAULT_PROJECT_ID: ${{ env.PROJECT_ID }}
SCW_DEFAULT_ORGANIZATION_ID: ${{ secrets.SCW_ORGANIZATION_ID }}
deploy-cron:
needs: build-and-push-images
runs-on: ubuntu-latest
environment: staging
steps:
- name: Install CLI
uses: scaleway/action-scw@v0
- name: Get container ID
run: |
echo "CONTAINER_ID=$(scw container container list namespace-id=${{env.NAMESPACE_ID}} -o json | jq -r '.[] | select(.name == "cron") | .id')" >> $GITHUB_ENV
env:
SCW_ACCESS_KEY: ${{ secrets.SCW_ACCESS_KEY }}
SCW_SECRET_KEY: ${{ secrets.SCW_SECRET_KEY }}
SCW_DEFAULT_PROJECT_ID: ${{ env.PROJECT_ID }}
SCW_DEFAULT_ORGANIZATION_ID: ${{ secrets.SCW_ORGANIZATION_ID }}
- name: Deploy the container based on the new image
run: |
env_string=""
while IFS= read -r line; do
if [[ "$line" == *"="* ]]; then
key=$(echo "$line" | cut -d '=' -f 1)
value=$(echo "$line" | cut -d '=' -f 2-)
if [[ -n "$key" ]]; then
env_string+="environment-variables.$key=$value "
fi
fi
done <<< "$ENV_VARS"
env_string=$(echo $env_string | sed 's/ $//')
scw container container update ${{ env.CONTAINER_ID }} $env_string
env:
ENV_VARS: ${{ secrets.ENV }}
SCW_ACCESS_KEY: ${{ secrets.SCW_ACCESS_KEY }}
SCW_SECRET_KEY: ${{ secrets.SCW_SECRET_KEY }}
SCW_DEFAULT_PROJECT_ID: ${{ env.PROJECT_ID }}
SCW_DEFAULT_ORGANIZATION_ID: ${{ secrets.SCW_ORGANIZATION_ID }}