Skip to content

Commit

Permalink
Attempt to merge deploy jobs into one
Browse files Browse the repository at this point in the history
  • Loading branch information
ldeluigi committed May 31, 2023
1 parent 85432d8 commit d6af496
Showing 1 changed file with 27 additions and 116 deletions.
143 changes: 27 additions & 116 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ jobs:
name: spellbook-backend
path: /tmp/spellbook-backend.tar

- name: Upload migration artifatcs 📦
uses: actions/upload-artifact@v3
with:
name: spellbook-backend-migrations
path: backend/.kubernetes/migration


lint:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -150,157 +156,89 @@ jobs:
release/*
push-ecr-current-version:
deploy:
runs-on: ubuntu-latest
needs: [build, release]
concurrency: production
concurrency:
group: production
cancel-in-progress: false
environment: scm-production
steps:
- name: SetupDocker Buildx 🐳
uses: docker/setup-buildx-action@v2

- name: Configure AWS credentials 🛠
uses: aws-actions/configure-aws-credentials@v2
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_REGION }}

- name: Login to Amazon ECR 📦
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1

- name: Download image artifact ⬇
uses: actions/download-artifact@v3
with:
name: spellbook-backend
path: /tmp

- name: Load image from artifact 🐳
run: |
docker load --input /tmp/spellbook-backend.tar
docker image ls -a
- name: Push image to Amazon ECR 📦
- name: Push versioned image to Amazon ECR 📦
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: ${{ secrets.AWS_ECR_REPO_NAME }}
IMAGE_TAG: ${{ needs.build.outputs.version }}
run: |
docker tag spellbook-backend:latest $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
run-migrations:
runs-on: ubuntu-latest
needs: [build, push-ecr-current-version]
environment: scm-production
steps:

- name: Checkout 🛎️
uses: actions/checkout@v3

- name: Configure AWS credentials 🛠
uses: aws-actions/configure-aws-credentials@v2
- name: Download migration artifacts ⬇
id: migration-artifacts
uses: actions/download-artifact@v3
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_REGION }}

- name: Login to Amazon ECR 📦
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1

- name: Config kube 🐙
working-directory: backend/.kubernetes/migration
run: aws eks --region us-east-2 update-kubeconfig --name spellbook-prod-cluster --kubeconfig spellbookkubeconfig.yaml

- name: Install and configure kubectl 🐙
name: spellbook-backend-migrations
path: /tmp/migrations
- name: Debug step # TODO: delete
run: |
VERSION=$(curl --silent https://storage.googleapis.com/kubernetes-release/release/stable.txt)
curl https://storage.googleapis.com/kubernetes-release/release/$VERSION/bin/linux/amd64/kubectl \
--progress-bar \
--location \
--remote-name
chmod +x kubectl
sudo mv kubectl /usr/local/bin/
echo ${{ steps.migration-artifacts.outputs.download-path }}
ls /tmp/migrations
- name: Configure kubernetes 🐙
working-directory: /tmp/migrations
run: aws eks --region ${{ secrets.AWS_REGION }} update-kubeconfig --name spellbook-prod-cluster --kubeconfig spellbookkubeconfig.yaml
- name: Install and configure kubectl 🐙
uses: azure/setup-kubectl@v3
- name: Setup Kustomize 🛠
uses: imranismail/setup-kustomize@v2

- name: Run Kustomize to set image to sha 🛠
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: ${{ secrets.AWS_ECR_REPO_NAME }}
IMAGE_TAG: ${{ needs.build.outputs.version }}
working-directory: backend/.kubernetes/migration
working-directory: /tmp/migrations
run: |
image_name=$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
kustomize edit set image $image_name
kustomize edit set image $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
- name: Run migrations 🚶‍♂️
working-directory: backend/.kubernetes/migration
working-directory: /tmp/migrations
run: |
export KUBECONFIG=spellbookkubeconfig.yaml
kubectl delete job spellbook-migration -n spellbook || true
kubectl apply -k .
kubectl wait --for=condition=complete job/spellbook-migration -n spellbook &
completion_pid=$!
kubectl wait --for=condition=failed job/spellbook-migration -n spellbook && exit 1 &
failure_pid=$!
exit_code=0
if wait -n $completion_pid $failure_pid; then
echo "Job completed successfully"
else
echo "Job failed"
exit_code=1
fi
echo "Job logs:"
kubectl logs job/spellbook-migration -n spellbook
echo "Deleting job..."
kubectl delete job/spellbook-migration -n spellbook
exit $exit_code
push-ecr-latest:
runs-on: ubuntu-latest
needs: run-migrations
environment: scm-production
steps:
- name: SetupDocker Buildx 🐳
uses: docker/setup-buildx-action@v2

- name: Configure AWS credentials 🛠
uses: aws-actions/configure-aws-credentials@v2
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_REGION }}

- name: Login to Amazon ECR 📦
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1

- name: Download image artifact ⬇
uses: actions/download-artifact@v3
with:
name: spellbook-backend
path: /tmp

- name: Load image from artifact 🐳
run: |
docker load --input /tmp/spellbook-backend.tar
docker image ls -a
- name: Push image to Amazon ECR 📦
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
Expand All @@ -309,33 +247,6 @@ jobs:
run: |
docker tag spellbook-backend:latest $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
rollout-pods:
runs-on: ubuntu-latest
needs: push-ecr-latest
environment: scm-production
steps:
- name: Configure AWS credentials 🛠
uses: aws-actions/configure-aws-credentials@v2
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_REGION }}

- name: Config kube 🐙
run: aws eks --region us-east-2 update-kubeconfig --name spellbook-prod-cluster --kubeconfig spellbookkubeconfig.yaml

- name: Install and configure kubectl 🐙
run: |
VERSION=$(curl --silent https://storage.googleapis.com/kubernetes-release/release/stable.txt)
curl https://storage.googleapis.com/kubernetes-release/release/$VERSION/bin/linux/amd64/kubectl \
--progress-bar \
--location \
--remote-name
chmod +x kubectl
sudo mv kubectl /usr/local/bin/
- name: Rollout pods 🚀
run: |
export KUBECONFIG=spellbookkubeconfig.yaml
Expand Down

0 comments on commit d6af496

Please sign in to comment.