Skip to content

Merge pull request #307 from LDSSA/release/v0.2.1 #39

Merge pull request #307 from LDSSA/release/v0.2.1

Merge pull request #307 from LDSSA/release/v0.2.1 #39

Workflow file for this run

name: CI - Build and Deploy
on:
push:
branches:
- main
- dev
jobs:
build-and-push:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./portal
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Store image tag
id: image_tag
run: echo "IMAGE_TAG=$(echo `git log -n1 --format='%h'`)" >> $GITHUB_ENV
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USER }}
password: ${{ secrets.DOCKER_PASS }}
- name: Build and Push django image
run: |
source $GITHUB_ENV
docker build -t ldssa/django:$IMAGE_TAG .
docker push ldssa/django:$IMAGE_TAG
deploy:
runs-on: ubuntu-latest
needs: build-and-push
defaults:
run:
working-directory: ./deploy
steps:
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: eu-west-1
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Kubernetes
uses: azure/setup-kubectl@v4
- name: Set up Helm
uses: azure/setup-helm@v4
- name: Get the short SHA
id: vars
run: echo "short_sha=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
- name: Deploy to Kubernetes
run: |
if [ ${{ github.ref }} == 'refs/heads/main' ]; then
cluster_name="production"
postgres_db="portal"
ingress_host="portal.lisbondatascience.org"
else
cluster_name="development"
postgres_db="portaldev"
ingress_host="portal.dev-lisbondatascience.org"
fi
aws eks update-kubeconfig --name $cluster_name
# Make sure that the cert-manager is installed
# kubectl apply -f https://github.com/cert-manager/cert-manager/releases/download/v1.13.0/cert-manager.yaml
# We need to get redis chart repository
helm repo add bitnami https://charts.bitnami.com/bitnami
# And NGINX
helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx
helm repo update
helm dependency update ldsa-portal
# Define the values file we want to use depending
# on the branch we are pushing to.
helm upgrade --install ldsa-portal ./ldsa-portal \
--values ./ldsa-portal/values.yaml \
--set image.tag=${{ env.short_sha }} \
--set postgres.db=$postgres_db \
--set ingress.host=$ingress_host