migrate before running app #22
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: | | |
aws eks update-kubeconfig --name portal-batch4 | |
helm dependency update ldsa-portal | |
# Define the values file we want to use depending | |
# on the branch we are pushing to. | |
if [ ${{ github.ref }} == 'refs/heads/main' ]; then | |
values_file="./ldsa-portal/values.yaml" | |
release_name="ldsa-portal" | |
else | |
values_file="./ldsa-portal/values-dev.yaml" | |
release_name="ldsa-portal-dev" | |
fi | |
helm upgrade --install $release_name ./ldsa-portal --values $values_file --set image.tag=${{ env.short_sha }} |