Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
olehmell committed May 9, 2024
2 parents fc506d2 + 9983b95 commit 484ef9e
Show file tree
Hide file tree
Showing 21 changed files with 301 additions and 418 deletions.
77 changes: 77 additions & 0 deletions .github/actions/common-cd-setup/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
name: Common CD setup
description: 'Sets up the environment for jobs during CD'

inputs:
token_input:
description: "the k8s temporary creds"
required: true
k8s_input:
description: "the cluster name"
required: true
app_input:
description: "the App name"
required: true
zone_input:
description: "the cf zone"
required: true
mail_input:
description: "the cf mail"
required: true
tokens_input:
description: "the cf token"
required: true
prod_deploy:
description: "deploy to prod or not, Boolean"
required: true

runs:
using: composite
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Extract main branch name
if: github.ref == 'refs/heads/main'
shell: bash
run: echo "name=${GITHUB_REF#refs/heads/}" >> $GITHUB_ENV
id: extract_branch

- name: Extract feature branch name
if: startsWith(github.ref, 'refs/heads/deploy/')
shell: bash
run: echo "name=$(echo ${GITHUB_REF#refs/heads/} | sed 's/^deploy\///')" >> $GITHUB_ENV
id: extract_features_branch

- name: Prepare
id: prep
shell: bash
run: |
echo "image=dappforce/subid-backend:${{ inputs.app_input }}-${{ env.name }}-$(echo $GITHUB_SHA | head -c7)" >> $GITHUB_ENV
- name: Install doctl
uses: digitalocean/action-doctl@v2
with:
token: ${{ inputs.token_input }}

- name: Save DigitalOcean kubeconfig with short-lived credentials
shell: bash
run: doctl kubernetes cluster kubeconfig save --expiry-seconds 600 ${{ inputs.k8s_input }}

- name: Add feature name
if: startsWith(github.ref, 'refs/heads/deploy/')
shell: bash
run: |
NAME=${{ env.name }} && sed -i 's|<BRANCH>|'${NAME}'|' $GITHUB_WORKSPACE/deployment/${{ inputs.app_input }}/all.yaml
NAME=${{ env.name }} && sed -i 's|<BRANCH>|'${NAME}'|' $GITHUB_WORKSPACE/deployment/${{ inputs.app_input }}/deployment.yaml
sed -i 's|<IMAGE>|'${{ env.image }}'|' $GITHUB_WORKSPACE/deployment/${{ inputs.app_input }}/deployment.yaml
curl -X POST "https://api.cloudflare.com/client/v4/zones/${{ inputs.zone_input }}/dns_records" -H "X-Auth-Email:${{ inputs.mail_input }}" -H "Authorization:Bearer ${{ inputs.tokens_input }}" -H "Content-Type:application/json" --data '{"type":"A","name":"${{ env.name }}-subid.subsocial.network","content":"174.138.105.155","ttl":3600,"priority":10,"proxied":true}'
kubectl apply -f $GITHUB_WORKSPACE/deployment/${{ inputs.app_input }}/
- name: make ${{ inputs.app_input }} ready
if: github.ref == 'refs/heads/main' && inputs.prod_deploy == false
shell: bash
run: |
sed -i 's|<IMAGE>|'${{ env.image }}'|' $GITHUB_WORKSPACE/deployment/${{ inputs.app_input }}/daemon.yaml
kubectl apply -f $GITHUB_WORKSPACE/deployment/${{ inputs.app_input }}/daemon.yaml
kubectl -n sub-id rollout status daemonset/back-ready
kubectl delete -f $GITHUB_WORKSPACE/deployment/${{ inputs.app_input }}/daemon.yaml
82 changes: 82 additions & 0 deletions .github/actions/common-ci-setup/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
name: Common CI setup
description: 'Sets up the environment for jobs during CI'

inputs:
username_input:
description: "the DockerHub username"
required: true
password_input:
description: "the DockerHub password"
required: true
app_input:
description: "the App name"
required: true

runs:
using: composite
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Extract main branch name
if: github.ref == 'refs/heads/main'
shell: bash
run: echo "name=${GITHUB_REF#refs/heads/}" >> $GITHUB_ENV
id: extract_branch

- name: Extract feature branch name
if: startsWith(github.ref, 'refs/heads/deploy/')
shell: bash
run: echo "name=$(echo ${GITHUB_REF#refs/heads/} | sed 's/^deploy\///')" >> $GITHUB_ENV
id: extract_features_branch

- name: Set up Docker context for buildx
id: buildx-context
shell: bash
run: |
docker context create builders
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@master
with:
endpoint: builders
version: latest

- name: Login to DockerHub
uses: docker/login-action@master
with:
username: ${{ inputs.username_input }}
password: ${{ inputs.password_input }}

- name: Cache Docker layers
uses: actions/cache@v4
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-single-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-single-buildx
- name: Prepare
id: prep
shell: bash
run: |
echo "image=dappforce/subid-backend:${{ inputs.app_input }}-${{ env.name }}-$(echo $GITHUB_SHA | head -c7)" >> $GITHUB_ENV
- name: Build image
uses: docker/build-push-action@v4
with:
context: .
builder: ${{ steps.buildx.outputs.name }}
file: docker/Dockerfile
push: true
tags: |
${{ env.image }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new

- name: Move cache
shell: bash
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
1 change: 1 addition & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ updates:
reviewers:
- "oap75"
- "samchuk-vlad"
- "iv1310"
schedule:
interval: "weekly"
commit-message:
Expand Down
Loading

0 comments on commit 484ef9e

Please sign in to comment.