Skip to content

Commit

Permalink
added CI/CD
Browse files Browse the repository at this point in the history
  • Loading branch information
NivEz committed Feb 2, 2024
1 parent 01930a2 commit 296e621
Show file tree
Hide file tree
Showing 5 changed files with 134 additions and 15 deletions.
21 changes: 21 additions & 0 deletions .github/actions/env-variables/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: 'Environment variables setup'
description: 'Sets up environment variables for workflows'

runs:
using: 'composite'
steps:
- name: Define variables
shell: bash
run: |
(
SHA=${GITHUB_SHA::7}
DOCKER_REGISTRY=mtz.ocir.io
echo "DOCKER_REPO=${DOCKER_REGISTRY}/${{ secrets.OCI_TENANCY_NAMESPACE }}/movie-info-bot"
echo "SHA=${SHA}"
echo "HOST=${{ secrets.HOST }}"
echo "TELEGRAM_API_TOKEN=${{ secrets.TELEGRAM_API_TOKEN }}"
echo "DOCKER_REGISTRY=${DOCKER_REGISTRY}"
echo "DOCKER_USERNAME=${{ secrets.OCI_TENANCY_NAMESPACE }}/${{ secrets.OCI_USERNAME }}"
echo "DOCKER_AUTH_TOKEN=${{ secrets.DOCKER_AUTH_TOKEN }}"
) >> $GITHUB_ENV
95 changes: 95 additions & 0 deletions .github/workflows/deploy-on-push.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
name: Deploy on push
on:
push:
branches:
- main

jobs:
build:
runs-on: ubuntu-latest
env:
DOCKER_REGISTRY: mtz.ocir.io
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set environment variables
uses: allenevans/set-env@v3.0.0
with:
DOCKER_REPO: '${{ env.DOCKER_REGISTRY }}/${{ secrets.OCI_TENANCY_NAMESPACE }}/movie-info-bot'
HOST: ${{ secrets.HOST }}
TELEGRAM_API_TOKEN: ${{ secrets.TELEGRAM_API_TOKEN }}
DOCKER_USERNAME: '${{ secrets.OCI_TENANCY_NAMESPACE }}/${{ secrets.OCI_USERNAME }}'

- name: Get short SHA
run: echo "SHA=${GITHUB_SHA::7}" >> $GITHUB_ENV

- name: Login to Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.DOCKER_REGISTRY }}
username: ${{ env.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_AUTH_TOKEN }}

# - name: Set up QEMU
# uses: docker/setup-qemu-action@v3

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

- name: Build and push
uses: docker/build-push-action@v5
with:
push: true
platforms: linux/amd64, linux/arm64
tags: |
${{ env.DOCKER_REPO }}:latest
${{ env.DOCKER_REPO }}:${{ env.SHA }}
# - name: Docker build
# run: docker build --platform linux/arm64 . -t ${{ env.DOCKER_REPO }}:latest

# - name: Docker tag
# run: docker tag ${{ env.DOCKER_REPO }}:latest ${{ env.DOCKER_REPO }}:${{ env.SHA }}

# - name: Docker push
# run: docker push ${{ env.DOCKER_REPO }} --all-tags

deploy:
runs-on: ubuntu-latest
needs: build
env:
OCI_CLI_USER: ${{ secrets.OCI_CLI_USER }}
OCI_CLI_TENANCY: ${{ secrets.OCI_CLI_TENANCY }}
OCI_CLI_FINGERPRINT: ${{ secrets.OCI_CLI_FINGERPRINT }}
OCI_CLI_KEY_CONTENT: ${{ secrets.OCI_CLI_KEY_CONTENT }}
OCI_CLI_REGION: ${{ secrets.OCI_CLI_REGION }}

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set environment variables
uses: allenevans/set-env@v3.0.0
with:
DOCKER_REGISTRY: mtz.ocir.io
DOCKER_REPO: '${DOCKER_REGISTRY}/${{ secrets.OCI_TENANCY_NAMESPACE }}/movie-info-bot'
DOCKER_USERNAME: '${{ secrets.OCI_TENANCY_NAMESPACE }}/${{ secrets.OCI_USERNAME }}'
DOCKER_AUTH_TOKEN: ${{ secrets.DOCKER_AUTH_TOKEN }}

- name: Get short SHA
run: echo "SHA=${GITHUB_SHA::7}" >> $GITHUB_ENV

- name: Configure Kubectl and kubeconfig
uses: oracle-actions/configure-kubectl-oke@v1.3.2
with:
cluster: ${{ secrets.OKE_CLUSTER_OCID }}

- name: Install Helm
uses: azure/setup-helm@v3

- name: Modify values.yaml
run: 'envsubst < ./.helm/template-values.yaml > ./.helm/values.yaml'

- name: Helm upgrade
run: helm upgrade -f .helm/values.yaml movie-info-bot ./.helm --atomic --debug --reuse-values
16 changes: 16 additions & 0 deletions .helm/template-values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
appName: movie-info-bot

deployment:
image: '${DOCKER_REPO}:${SHA}'
sha: '${SHA}'

ingress:
host: '${HOST}'

appEnv:
apiToken: '${TELEGRAM_API_TOKEN}'

imageCredentials:
registry: '${DOCKER_REGISTRY}'
username: '${DOCKER_USERNAME}'
password: '${DOCKER_AUTH_TOKEN}'
2 changes: 2 additions & 0 deletions .helm/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ metadata:
namespace: {{ .Values.appName }}
labels:
app: {{ .Values.appName }}
sha: {{ .Values.deployment.sha }}
spec:
selector:
matchLabels:
Expand All @@ -13,6 +14,7 @@ spec:
metadata:
labels:
app: {{ .Values.appName }}
sha: {{ .Values.deployment.sha }}
spec:
containers:
- name: {{ .Values.appName }}
Expand Down
15 changes: 0 additions & 15 deletions .helm/values.yaml

This file was deleted.

0 comments on commit 296e621

Please sign in to comment.