[chore][SRE-362]: setup resource limit #17
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: CI/CD pipeline for Sandbox | |
on: | |
push: | |
branches: | |
- develop | |
- feature/SRE-362-github-actions | |
env: | |
# Manage your service | |
SERVICE_NAME: ome | |
# Defaults for docker | |
ENVIRONMENT_NAME: sandbox | |
DOCKERFILE: ./Dockerfile | |
DOCKER_COMPOSE: .deployment/docker-compose.yaml | |
DOCKER_COMPOSE_DEPLOY: .deployment/compose-deploy.yaml | |
COMPOSE_ENV_FILE: .deployment/.env | |
COMPOSE_APP_ENV_FILE: .deployment/.env.compose | |
jobs: | |
dockerize: | |
name: Build and Push Docker image to Registry | |
runs-on: ubuntu-20.04 | |
environment: sandbox | |
steps: | |
- | |
name: Fetch Repository | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 2 | |
- | |
# Add support for more platforms with QEMU (optional) | |
# https://github.com/docker/setup-qemu-action | |
name: Setup QEMU | |
uses: docker/[email protected] | |
- | |
name: Setup Docker Buildx | |
uses: docker/[email protected] | |
- | |
name: Login to GitHub Container Registry | |
uses: docker/[email protected] | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- | |
name: Setup Lowercase Repository | |
id: repository | |
uses: ASzc/change-string-case-action@v5 | |
with: | |
string: ${{ github.repository }} | |
- | |
name: Set version output | |
id: vars | |
run: | | |
echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_ENV | |
- | |
name: Build and Push Container image | |
uses: docker/build-push-action@v5 | |
with: | |
file: ${{ env.DOCKERFILE }} | |
platforms: linux/amd64 | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
push: true | |
target: release | |
tags: | | |
ghcr.io/${{ steps.repository.outputs.lowercase }}:develop | |
ghcr.io/${{ steps.repository.outputs.lowercase }}:${{ env.sha_short }} | |
deploy: | |
name: Deploy Sandbox Service | |
runs-on: [self-hosted, linux, x64, ome-poc, hybiot, internal] | |
environment: sandbox | |
needs: | |
- dockerize | |
steps: | |
- | |
name: Setup Lowercase Repository | |
id: repository | |
uses: ASzc/change-string-case-action@v5 | |
with: | |
string: ${{ github.repository }} | |
- | |
name: Fetch Repository | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 2 | |
- | |
name: Login to GitHub Container Registry | |
uses: docker/[email protected] | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- | |
name: Set version output | |
id: vars | |
run: | | |
echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_ENV | |
- | |
name: Create env Docker-Compose | |
run: | | |
touch ${{ env.COMPOSE_ENV_FILE }} | |
echo '' > ${{ env.COMPOSE_ENV_FILE }} | |
echo IMAGE_NAME=ghcr.io/${{ steps.repository.outputs.lowercase }} >> ${{ env.COMPOSE_ENV_FILE }} | |
echo IMAGE_TAG=${{ env.sha_short }} >> ${{ env.COMPOSE_ENV_FILE }} | |
echo SERVICE_NAME=${{ env.SERVICE_NAME }} >> ${{ env.COMPOSE_ENV_FILE }} | |
touch ${{ env.COMPOSE_APP_ENV_FILE }} | |
cat .deployment/.env.${{ env.ENVIRONMENT_NAME }} >> ${{ env.COMPOSE_APP_ENV_FILE }} | |
envsubst < ${{ env.DOCKER_COMPOSE }} > ${{ env.DOCKER_COMPOSE_DEPLOY }} | |
env: | |
IMAGE_NAME: ghcr.io/${{ steps.repository.outputs.lowercase }} | |
IMAGE_TAG: ${{ env.sha_short }} | |
SERVICE_NAME: ${{ env.SERVICE_NAME }} | |
- | |
name: Starting docker compose services | |
run: | | |
docker compose -f ${{ env.DOCKER_COMPOSE_DEPLOY }} pull | |
docker compose -f ${{ env.DOCKER_COMPOSE_DEPLOY }} up -d | |
docker ps -a | |
env: | |
COMPOSE_HTTP_TIMEOUT: 600 | |
SERVICE_NAME: ${{ env.SERVICE_NAME }} | |
notify: | |
name: Discord Notification | |
runs-on: ubuntu-20.04 | |
needs: | |
- dockerize | |
- deploy | |
if: ${{ always() }} | |
steps: | |
- name: Notify | |
uses: nobrayner/discord-webhook@v1 | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
discord-webhook: ${{ secrets.ACTIONS_DISCORD_WEBHOOK }} | |
title: '{{STATUS}} : ${{ github.workflow }}' | |
description: '[${{ github.sha }}](https://github.com/${{ github.repository }}/commit/${{ github.sha }})' | |
include-details: 'true' | |
color-success: '#1a7f37' | |
color-failure: '#cf222e' | |
color-cancelled: '#7c848d' |