Init commit #21
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: Update Dashboards & Deploy | |
on: | |
push: | |
branches: | |
- main | |
jobs: | |
update-dashboards: | |
name: Update Dashboards | |
runs-on: self-hosted | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Install dependencies | |
run: sudo apt-get install -y jq | |
- name: Get UNIX_TIMESTAMP | |
run: | | |
UNIX_TIMESTAMP=$(date +%s) | |
echo "UNIX_TIMESTAMP=$UNIX_TIMESTAMP" >> $GITHUB_ENV | |
- name: Run update_dashboards.sh | |
env: | |
DASHBOARD_DIR: "./grafana/dashboards" | |
GRAFANA_URL: ${{ secrets.GRAFANA_URL }} | |
GRAFANA_API_KEY: ${{ secrets.GRAFANA_API_KEY }} | |
COMMIT_MESSAGE: ${{ github.event.head_commit.message }} | |
UNIX_TIMESTAMP: ${{ env.UNIX_TIMESTAMP }} | |
run: | | |
chmod +x grafana/update_dashboards.sh | |
./grafana/update_dashboards.sh | |
deploy: | |
name: Deploy Grafana | |
runs-on: self-hosted | |
needs: update-dashboards | |
env: | |
GRAFANA_HOST: "10.10.0.108" | |
DOCKER_CONTEXT_NAME: grafana-ctx | |
DOCKER_PROJECT_NAME: grafana | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Run command on remote server via SSH | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ env.GRAFANA_HOST }} | |
username: ${{ secrets.SSH_USERNAME }} | |
password: ${{ secrets.SSH_PASSWORD }} | |
script: | | |
cd /data/grafana | |
git pull origin main | |
- name: Set up Docker context | |
run: | | |
docker context \ | |
create ${{ env.DOCKER_CONTEXT_NAME }} \ | |
--docker host="tcp://${{ env.GRAFANA_HOST }}:2375" | |
- name: Deploy with Docker Compose | |
run: | | |
docker --context ${{ env.DOCKER_CONTEXT_NAME }} compose \ | |
--project-name ${{ env.DOCKER_PROJECT_NAME }} up -d --remove-orphans --force-recreate | |
- name: Cleanup Docker context | |
if: always() | |
run: | | |
docker context rm ${{ env.DOCKER_CONTEXT_NAME }} --force |