Skip to content

Commit

Permalink
updated github workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
ParzivalEugene committed May 15, 2024
1 parent 55ce8d5 commit f0576b1
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 31 deletions.
63 changes: 63 additions & 0 deletions .github/workflows/build-and-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: Build, Test and Deploy to DigitalOcean

on:
workflow_dispatch:
# on:
# push:
# branches:
# - production

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Login to GitHub Container Registry
run: docker login ghcr.io -u ${{ github.actor }} -p ${{ secrets.GHCR_PAT }}

- name: Set ghcr.io url
run: echo "REPO=${GITHUB_REPOSITORY@L}" >> "${GITHUB_ENV}"

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Build the Docker image
run: |
docker build . -t ghcr.io/${{ env.REPO }}:${{ github.sha }}
docker tag ghcr.io/${{ env.REPO }}:${{ github.sha }} ghcr.io/${{ env.REPO }}:latest
- name: Push the Docker image
run: |
docker push ghcr.io/${{ env.REPO }}:${{ github.sha }}
docker push ghcr.io/${{ env.REPO }}:latest
deploy:
needs: build
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Add SSH key
run: |
mkdir -p ~/.ssh
echo "${{ secrets.HELIOS_SSH }}" > ~/.ssh/helios_ssh
chmod 600 ~/.ssh/helios_ssh
- name: Setup to DigitalOcean
run: |
ssh -o StrictHostKeyChecking=no -i ~/.ssh/helios_ssh -p ${{ secrets.SSH_PORT }} ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }} "echo ${{ secrets.GHCR_PAT }} | docker login ghcr.io -u ${{ github.actor }} --password-stdin"
ssh -o StrictHostKeyChecking=no -i ~/.ssh/helios_ssh -p ${{ secrets.SSH_PORT }} ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }} "rm -f docker-compose.yml"
ssh -o StrictHostKeyChecking=no -i ~/.ssh/helios_ssh -p ${{ secrets.SSH_PORT }} ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }} "rm -f .env"
ssh -o StrictHostKeyChecking=no -i ~/.ssh/helios_ssh -p ${{ secrets.SSH_PORT }} ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }} "rm -rf traefik/"
scp -o StrictHostKeyChecking=no -i ~/.ssh/helios_ssh -P ${{ secrets.SSH_PORT }} docker-compose.yml ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }}:~/docker-compose.yml
scp -o StrictHostKeyChecking=no -i ~/.ssh/helios_ssh -P ${{ secrets.SSH_PORT }} .env ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }}:~/.env
scp -o StrictHostKeyChecking=no -i ~/.ssh/helios_ssh -P ${{ secrets.SSH_PORT }} -r traefik/ ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }}:~/traefik/
- name: Deploy to DigitalOcean
run: |
ssh -i ~/.ssh/helios_ssh -p ${{ secrets.SSH_PORT }} ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }} "docker compose down"
ssh -i ~/.ssh/helios_ssh -p ${{ secrets.SSH_PORT }} ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }} "docker compose pull"
ssh -i ~/.ssh/helios_ssh -p ${{ secrets.SSH_PORT }} ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }} "docker compose up -d"
10 changes: 6 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
name: Build and Push Docker Image
name: Build docker image

on:
push:
branches:
- production
workflow_dispatch:
# on:
# push:
# branches:
# - production

jobs:
build:
Expand Down
28 changes: 1 addition & 27 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -1,38 +1,12 @@
name: Build, Test and Deploy to DigitalOcean
name: Deploy to DigitalOcean

on:
workflow_dispatch:
# on:
# push:
# branches:
# - production

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Login to GitHub Container Registry
run: docker login ghcr.io -u ${{ github.actor }} -p ${{ secrets.GHCR_PAT }}

- name: Set ghcr.io url
run: echo "REPO=${GITHUB_REPOSITORY@L}" >> "${GITHUB_ENV}"

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Build the Docker image
run: |
docker build . -t ghcr.io/${{ env.REPO }}:${{ github.sha }}
docker tag ghcr.io/${{ env.REPO }}:${{ github.sha }} ghcr.io/${{ env.REPO }}:latest
- name: Push the Docker image
run: |
docker push ghcr.io/${{ env.REPO }}:${{ github.sha }}
docker push ghcr.io/${{ env.REPO }}:latest
deploy:
needs: build
runs-on: ubuntu-latest
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/setup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ jobs:
- name: Setup DigitalOcean droplet
run: |
ssh -o StrictHostKeyChecking=no -i ~/.ssh/helios_ssh -p ${{ secrets.SSH_PORT }} ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }} "echo ${{ secrets.GHCR_PAT }} | docker login ghcr.io -u ${{ github.actor }} --password-stdin"
ssh -o StrictHostKeyChecking=no -i ~/.ssh/helios_ssh -p ${{ secrets.SSH_PORT }} ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }} "docker plugin install grafana/loki-docker-driver:2.9.2 --alias loki --grant-all-permissions"
ssh -o StrictHostKeyChecking=no -i ~/.ssh/helios_ssh -p ${{ secrets.SSH_PORT }} ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }} "rm -f docker-compose.yml"
ssh -o StrictHostKeyChecking=no -i ~/.ssh/helios_ssh -p ${{ secrets.SSH_PORT }} ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }} "rm -f .env"
ssh -o StrictHostKeyChecking=no -i ~/.ssh/helios_ssh -p ${{ secrets.SSH_PORT }} ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }} "rm -rf traefik/"
Expand Down

0 comments on commit f0576b1

Please sign in to comment.