Created
January 14, 2024 18:24
-
-
Save theCaptN21/835bde8949eba14b4b447d78d2773240 to your computer and use it in GitHub Desktop.
New GHA Pipeline
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: Docker Nginx ECS Build, Test, & Log Creation | |
on: | |
push: | |
branches: | |
- main | |
jobs: | |
create-ecs-repo: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Create ECS Repository | |
run: | | |
aws configure set aws_access_key_id ${{ secrets.AWS_ACCESS_KEY_ID }} | |
aws configure set aws_secret_access_key ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
aws configure set region ${{ secrets.AWS_REGION }} | |
aws ecr create-repository --repository-name ${{ secrets.IMAGE_NAME }} || true | |
build-and-push: | |
needs: create-ecs-repo | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
environment: [dev] | |
env: | |
AWS_DEFAULT_REGION: ${{ secrets.AWS_REGION }} | |
IMAGE_NAME: ${{ secrets.IMAGE_NAME }} | |
IMAGE_TAG: ${{ github.sha }} | |
ECS_REPO: ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.${{ secrets.AWS_REGION }}.amazonaws.com/${{ secrets.IMAGE_NAME }} | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Setup AWS CLI | |
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: Build Docker Nginx Image | |
run: | | |
docker build -t $IMAGE_NAME:$IMAGE_TAG -f Dockerfile . | |
docker tag $IMAGE_NAME:$IMAGE_TAG $ECS_REPO:$IMAGE_TAG | |
- name: Push Docker Nginx Image to ECS | |
run: | | |
aws ecr get-login-password --region $AWS_DEFAULT_REGION | docker login --username AWS --password-stdin $ECS_REPO | |
docker push $ECS_REPO:$IMAGE_TAG | |
test: | |
needs: build-and-push | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Install Dependencies and Verify | |
run: | | |
sudo apt-get update | |
sudo apt-get install -y curl | |
curl --version | |
docker --version | |
create-logs: | |
needs: test | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Setup AWS CLI | |
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: Setup CloudWatch Logs | |
run: | | |
chmod +x logs.sh | |
./logs.sh |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment