Skip to content

chore(misc): Manual deploy environment #30

chore(misc): Manual deploy environment

chore(misc): Manual deploy environment #30

name: Deploy environment
on:
workflow_dispatch:
pull_request:
types: [ labeled, synchronize, opened, reopened ]
concurrency:
group: ${{ github.workflow }}-${{ github.ref_name }}
cancel-in-progress: true
jobs:
prepare:
if: |
(github.event_name=='pull_request' && contains(github.event.pull_request.labels.*.name, 'deploy')) ||
(github.event_name=='workflow_dispatch' && github.ref_name != 'production' && github.ref_name != 'main')
runs-on: ubuntu-latest
outputs:
env_name: ${{ steps.config.outputs.env_name }}
build_matrix: ${{ steps.config.outputs.build }}
deploy_matrix: ${{ steps.config.outputs.deploy }}
steps:
- uses: actions/checkout@v4
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: "20.17"
- name: Get environment configuration
env:
BRANCH_NAME: ${{ github.event.pull_request.head.ref || github.ref_name }}
id: config
run: |
# ENV_NAME
env_name=$(node devops/scripts/get-environment-name.js ${{ env.BRANCH_NAME }})
echo "env_name: $env_name"
echo "env_name=$env_name" >> $GITHUB_OUTPUT
git fetch --depth=100 origin ${{ env.BRANCH_NAME }}
git switch ${{ env.BRANCH_NAME }}
# BUILD MATRIX
echo "[]" \
| jq '. + [{name:"api", tag:$tag}]' --arg tag "$(git log --max-count=1 --oneline -- api packages/lib package-lock.json | cut -d " " -f 1)" \
| jq '. + [{name:"apiv2", tag:$tag}]' --arg tag "$(git log --max-count=1 --oneline -- apiv2 packages/lib package-lock.json | cut -d " " -f 1)" \
| jq '. + [{name:"app", tag:$tag}]' --arg tag "$(git log --max-count=1 --oneline -- app packages package-lock.json | cut -d " " -f 1)" \
| jq '. + [{name:"admin", tag:$tag}]' --arg tag "$(git log --max-count=1 --oneline -- admin packages package-lock.json | cut -d " " -f 1)" > build.json
echo "Build matrix"
cat build.json
echo "build=$(jq -c < build.json)" >> $GITHUB_OUTPUT
# DEPLOY MATRIX
cat build.json > deploy.json
echo "Deploy matrix"
cat deploy.json
echo "deploy=$(jq -c < deploy.json)" >> $GITHUB_OUTPUT
create_environment:
needs: prepare
runs-on: ubuntu-latest
outputs:
registry: ${{ steps.registry.outputs.registry }}
steps:
- uses: actions/checkout@v4
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: "20.17"
- name: Create environment
id: registry
working-directory: devops/scripts
env:
SCW_ORGANIZATION_ID: ${{ secrets.SCW_ORGANIZATION_ID }}
SCW_SECRET_KEY: ${{ secrets.SCW_CI_DEPLOY_SECRET_KEY }}
run: |
node create-environment.js ${{ needs.prepare.outputs.env_name }}
registry=$(node get-environment-registry.js ${{ needs.prepare.outputs.env_name }})
echo "registry: $registry"
echo "registry=$registry" >> $GITHUB_OUTPUT
build:
needs: [prepare, create_environment]
runs-on: ubuntu-latest
strategy:
matrix:
app: ${{ fromJSON(needs.prepare.outputs.build_matrix) }}
steps:
- uses: actions/checkout@v4
- name: Login to Docker Container Registry
uses: docker/login-action@v2
with:
username: nologin
password: ${{ secrets.SCW_CI_DEPLOY_SECRET_KEY }}
registry: ${{ needs.create_environment.outputs.registry }}
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: "20.17"
- name: Build image
working-directory: devops/scripts
env:
SCW_ORGANIZATION_ID: ${{ secrets.SCW_ORGANIZATION_ID }}
SCW_SECRET_KEY: ${{ secrets.SCW_CI_DEPLOY_SECRET_KEY }}
run: |
node build-application-docker.js --push ${{ needs.prepare.outputs.env_name }} ${{matrix.app.name}} ${{matrix.app.tag}}
deploy:
needs: [prepare, build]
runs-on: ubuntu-latest
strategy:
matrix:
app: ${{ fromJSON(needs.prepare.outputs.deploy_matrix) }}
steps:
- uses: actions/checkout@v4
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: "20.17"
- name: Deploy image on Scaleway
working-directory: devops/scripts
env:
SCW_ORGANIZATION_ID: ${{ secrets.SCW_ORGANIZATION_ID }}
SCW_SECRET_KEY: ${{ secrets.SCW_CI_DEPLOY_SECRET_KEY }}
run: |
node deploy-scaleway.js ${{ needs.prepare.outputs.env_name }} ${{matrix.app.name}} ${{matrix.app.tag}}