modified dockerfile and deployment files #24
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: release | |
on: | |
push: | |
branches: | |
- main | |
- deploy | |
env: | |
REGISTRY: ghcr.io | |
IMAGE_NAME: outposthq/comet-search | |
IMAGE_TAG: latest-${{ github.run_number }} | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: setup docker buildx | |
uses: docker/setup-buildx-action@v2 | |
- uses: docker/metadata-action@v3 | |
id: metadata | |
with: | |
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | |
- uses: docker/login-action@v1 | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: build and push docker image | |
uses: docker/build-push-action@v4 | |
with: | |
push: true | |
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }} | |
labels: ${{ steps.metadata.outputs.labels }} | |
cache: true | |
cache-repository: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}/cache | |
deploy: | |
needs: build | |
name: Deploy to Kubernetes Cluster | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- uses: docker/metadata-action@v3 | |
id: metadata | |
with: | |
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | |
- uses: docker/login-action@v1 | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: using kubectl | |
uses: tale/kubectl-action@v1 | |
with: | |
base64-kube-config: ${{ secrets.SECRETS_CONFIG }} | |
- name: Check Current Service Deployment | |
run: | | |
CURRENT_DEPLOYMENT=$(kubectl get service comet-search-svc -n outpost -o jsonpath='{.spec.selector.app}') | |
echo "Current deployment: $CURRENT_DEPLOYMENT" | |
if [[ "$CURRENT_DEPLOYMENT" == "blue-comet-search" ]]; then | |
echo "Updating green deployment and service..." | |
sed -i "s|image: ghcr.io/outposthq/comet-search:latest|image: ghcr.io/outposthq/comet-search:${{ env.IMAGE_TAG }}|" green-deployment.yml | |
kubectl apply -f green-deployment.yml | |
sleep 10 | |
kubectl patch service comet-search-svc -p '{"spec":{"selector":{"app":"green-comet-search"}}}' -n outpost | |
sleep 5 | |
kubectl scale deployment blue-comet-search --replicas=0 -n outpost | |
elif [[ "$CURRENT_DEPLOYMENT" == "green-comet-search" ]]; then | |
echo "Updating blue deployment and service..." | |
sed -i "s|image: ghcr.io/outposthq/comet-search:latest|image: ghcr.io/outposthq/comet-search:${{ env.IMAGE_TAG }}|" blue-deployment.yml | |
kubectl apply -f blue-deployment.yml | |
sleep 10 | |
kubectl patch service comet-search-svc -p '{"spec":{"selector":{"app":"blue-comet-search"}}}' -n outpost | |
sleep 5 | |
kubectl scale deployment green-comet-search --replicas=0 -n outpost | |
else | |
echo "Unknown deployment detected. Exiting..." | |
exit 1 | |
fi |