81 lines
2.7 KiB
YAML
81 lines
2.7 KiB
YAML
name: Deploy dev environment to kubernetes cluster
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
|
|
jobs:
|
|
build:
|
|
name: Build and push image
|
|
runs-on: ubuntu-latest
|
|
container:
|
|
image: ghcr.io/catthehacker/ubuntu:act-latest
|
|
steps:
|
|
- name: Check out repository code
|
|
uses: actions/checkout@v3
|
|
- name: Get composer.json content
|
|
id: get-version
|
|
uses: ActionsTools/read-json-action@main
|
|
with:
|
|
file_path: "composer.json"
|
|
- name: Get short SHA
|
|
id: get-short-sha
|
|
run: |
|
|
id=$(echo ${{ github.sha }} | cut -c 1-7)
|
|
echo "::set-output name=id::$id"
|
|
- name: Login to registry
|
|
uses: docker/login-action@v3
|
|
with:
|
|
registry: git.winteraccess.id
|
|
username: ${{ vars.REGISTRY_USER }}
|
|
password: ${{ secrets.REGISTRY_TOKEN }}
|
|
- name: Build and push to registry
|
|
uses: docker/build-push-action@v5
|
|
with:
|
|
context: .
|
|
file: deploy/docker/Dockerfile
|
|
push: true
|
|
tags: |
|
|
git.winteraccess.id/${{ gitea.repository }}:${{ steps.get-version.outputs.version }}main${{ steps.get-short-sha.outputs.id }}
|
|
deploy:
|
|
name: Deploy to kubernetes cluster
|
|
runs-on: ubuntu-latest
|
|
needs:
|
|
- build
|
|
container:
|
|
image: ghcr.io/catthehacker/ubuntu:act-latest
|
|
steps:
|
|
- name: Check out repository code
|
|
uses: actions/checkout@v3
|
|
- name: Get composer.json content
|
|
id: get-version
|
|
uses: ActionsTools/read-json-action@main
|
|
with:
|
|
file_path: "composer.json"
|
|
- name: Get short SHA
|
|
id: get-short-sha
|
|
run: |
|
|
id=$(echo ${{ github.sha }} | cut -c 1-7)
|
|
echo "::set-output name=id::$id"
|
|
- name: Create Kubeconfig
|
|
run: |
|
|
mkdir $HOME/.kube
|
|
echo "${{ secrets.KUBECONFIG }}" > $HOME/.kube/config
|
|
- name: Setup Kubectl
|
|
uses: azure/setup-kubectl@v4
|
|
- name: Set the Kubernetes context
|
|
uses: azure/k8s-set-context@v2
|
|
with:
|
|
method: service-account
|
|
k8s-url: ${{ vars.KUBE_URL }}
|
|
k8s-secret: ${{ secrets.KUBE_SECRET }}
|
|
- name: Deploy to the Kubernetes cluster
|
|
uses: azure/k8s-deploy@v5
|
|
with:
|
|
action: deploy
|
|
namespace: internship-pos-live
|
|
manifests: |
|
|
deploy/kubernetes/live.yaml
|
|
images: |
|
|
git.winteraccess.id/${{ gitea.repository }}:${{ steps.get-version.outputs.version }}main${{ steps.get-short-sha.outputs.id }}
|