Update docker-build.yml #12
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: Build and Deploy Docker Image | |
on: | |
push: | |
branches: | |
- main | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Debug AWS Secrets | |
env: | |
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
AWS_REGION: ${{ secrets.AWS_REGION }} | |
run: | | |
echo "AWS_ACCESS_KEY_ID: ${#AWS_ACCESS_KEY_ID} characters long" | |
echo "AWS_SECRET_ACCESS_KEY: ${#AWS_SECRET_ACCESS_KEY} characters long" | |
echo "AWS_REGION: ${AWS_REGION}" | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v1 | |
- name: prepare for aws cred | |
run: | | |
/usr/local/bin/first_script.sh | |
unset AWS_DEFAULT_REGION | |
unset AWS_REGION | |
unset AWS_ACCESS_KEY_ID unset AWS_SECRET_ACCESS_KEY unset AWS_SESSION_TOKEN | |
- name: Configure AWS credentials | |
uses: aws-actions/configure-aws-credentials@v1 | |
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: Log AWS Region | |
run: | | |
echo "AWS Region: ${{ secrets.AWS_REGION }}" | |
- name: Log in to Amazon ECR | |
run: | | |
aws ecr get-login-password --region ${{ secrets.AWS_REGION }} | docker login --username AWS --password-stdin ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.${{ secrets.AWS_REGION }}.amazonaws.com | |
- name: Build Docker image | |
run: docker build -t note-keeping-app:latest . | |
- name: Tag Docker image | |
run: docker tag note-keeping-app:latest ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.${{ secrets.AWS_REGION }}.amazonaws.com/note-keeping-app:latest | |
- name: Push Docker image to Amazon ECR | |
run: docker push ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.${{ secrets.AWS_REGION }}.amazonaws.com/note-keeping-app:latest | |
deploy: | |
needs: build | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Configure AWS credentials | |
uses: aws-actions/configure-aws-credentials@v1 | |
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: Set up kubectl | |
run: | | |
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl" | |
chmod +x kubectl | |
sudo mv kubectl /usr/local/bin/ | |
- name: Create kubeconfig file | |
run: | | |
echo "${{ secrets.KUBECONFIG }}" > $HOME/.kube/config | |
- name: Install Helm | |
run: | | |
curl https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 | bash | |
- name: Deploy to Kubernetes using Helm | |
run: | | |
helm upgrade --install note-keeping-app ./helm/note-keeping-app --namespace default --set image.repository=${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.${{ secrets.AWS_REGION }}.amazonaws.com/note-keeping-app --set image.tag=latest |