Accessibility and Redeployment #23
This file contains hidden or 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: workflow | |
| on: | |
| push: | |
| branches: | |
| - main | |
| paths-ignore: | |
| - "README.md" | |
| jobs: | |
| # ---------------- CI JOB ---------------- | |
| integration: | |
| name: Continuous Integration | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout Code | |
| uses: actions/checkout@v3 | |
| - name: Lint Code | |
| run: echo "Linting repository" | |
| - name: Run Unit Tests | |
| run: echo "Running unit tests" | |
| # ---------------- BUILD & PUSH JOB ---------------- | |
| build-and-push-ecr-image: | |
| name: Build & Push to ECR | |
| needs: integration | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout Code | |
| uses: actions/checkout@v3 | |
| - name: Install Utilities | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y jq unzip | |
| - 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: Login to Amazon ECR | |
| id: login-ecr | |
| uses: aws-actions/amazon-ecr-login@v1 | |
| - name: Build, Tag & Push Image | |
| env: | |
| ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} | |
| ECR_REPOSITORY: ${{ secrets.ECR_REPOSITORY_NAME }} | |
| IMAGE_TAG: latest | |
| run: | | |
| docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG . | |
| docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG | |
| # ---------------- DEPLOY JOB ---------------- | |
| deploy-to-ec2: | |
| name: Deploy on EC2 | |
| needs: build-and-push-ecr-image | |
| runs-on: self-hosted | |
| steps: | |
| - name: Checkout Code | |
| uses: actions/checkout@v3 | |
| - 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: Login to Amazon ECR | |
| uses: aws-actions/amazon-ecr-login@v1 | |
| - name: Pull Latest Image | |
| env: | |
| ECR_REGISTRY: ${{ secrets.AWS_ECR_LOGIN_URI }} | |
| ECR_REPOSITORY: ${{ secrets.ECR_REPOSITORY_NAME }} | |
| run: | | |
| docker pull $ECR_REGISTRY/$ECR_REPOSITORY:latest | |
| - name: Stop Old Container | |
| run: | | |
| docker stop mltest || true | |
| docker rm mltest || true | |
| - name: Run New Container | |
| env: | |
| ECR_REGISTRY: ${{ secrets.AWS_ECR_LOGIN_URI }} | |
| ECR_REPOSITORY: ${{ secrets.ECR_REPOSITORY_NAME }} | |
| run: | | |
| docker run -d \ | |
| --name mltest \ | |
| -p 8080:8080 \ | |
| $ECR_REGISTRY/$ECR_REPOSITORY:latest | |
| - name: Cleanup | |
| run: | | |
| docker system prune -f |