diff --git a/.github/workflows/backend-cd.yml b/.github/workflows/backend-cd.yml new file mode 100644 index 00000000..3e12e9e1 --- /dev/null +++ b/.github/workflows/backend-cd.yml @@ -0,0 +1,177 @@ +name: Backend CD + +on: + push: + branches: + - main + paths: + - 'starter/backend/**' + workflow_dispatch: + +jobs: + lint: + runs-on: ubuntu-latest + + steps: + - name: Checkout Repository + uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: '3.9' + + - name: Install pipenv + run: | + python -m pip install pipenv + + - name: Install Dependencies + run: | + cd starter/backend + pipenv install + + - name: Install flake8 + run: | + cd starter/backend + pipenv run pip install flake8 + + - name: Lint Code + run: | + cd starter/backend + pipenv run flake8 + + - name: Lint Code + run: | + cd starter/backend + pipenv run lint + + test: + runs-on: ubuntu-latest + + steps: + - name: Checkout Repository + uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: '3.9' + + - name: Install pipenv + run: | + python -m pip install pipenv + + - name: Install Dependencies + run: | + cd starter/backend + pipenv install + + - name: Run Tests + run: | + cd starter/backend + pipenv run test + + build: + runs-on: ubuntu-latest + needs: [lint, test] + + steps: + - name: Checkout Repository + uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: '3.9' + + - name: Install pipenv + run: | + python -m pip install pipenv + + - name: Install Dependencies + run: | + cd starter/backend + pipenv installku + + - name: Configure AWS credentials + uses: aws-actions/configure-aws-credentials@v4 + with: + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + aws-region: us-east-1 + + - name: Login to Amazon ECR + id: login-ecr + uses: aws-actions/amazon-ecr-login@v2 + + - name: Build, tag, and push image to Amazon ECR + env: + ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} + ECR_REPOSITORY: backend + IMAGE_TAG: ${{ github.sha }} + run: | + aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin 947772818907.dkr.ecr.us-east-1.amazonaws.com + cd starter/backend/ + docker build -t backend . + docker tag backend:latest 947772818907.dkr.ecr.us-east-1.amazonaws.com/backend:latest + docker push 947772818907.dkr.ecr.us-east-1.amazonaws.com/backend:latest + + - name: Install kubectl + run: | + curl -sLO https://storage.googleapis.com/kubernetes-release/release/v1.19.9/bin/linux/amd64/kubectl + chmod +x ./kubectl + sudo mv ./kubectl /usr/local/bin/ + + - name: Check kubectl version + run: kubectl version --client + + - name: Display kubectl help + run: kubectl help + + - name: Install Kustomize + run: | + curl -s "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" | bash + sudo mv kustomize /usr/local/bin/ + + + - name: Check Kustomize version + run: kustomize version + + - name: Update AWS CLI + run: | + sudo apt-get install -y awscli + aws --version + + + - name: Add AWS EKS cluster to kubeconfig + run: | + # Specify AWS EKS cluster details + AWS_REGION=us-east-1 + EKS_CLUSTER_NAME=cluster + + # Set the path for the kubeconfig file + KUBECONFIG_PATH=/home/runner/.kube/config + + # Update kubeconfig with AWS EKS cluster + aws eks --region ${AWS_REGION} update-kubeconfig --name ${EKS_CLUSTER_NAME} --kubeconfig $KUBECONFIG_PATH + + + # Display the updated kubeconfig content (optional, for verification) + cat $KUBECONFIG_PATH + + env: + KUBECONFIG: /home/runner/.kube/config + + - name: Check kubectl commands + run: kubectl get pods + + - name: Deploy to EKS + run: | + cd starter/backend/k8s + kustomize edit set image backend=947772818907.dkr.ecr.us-east-1.amazonaws.com/backend:latest + + + - name: Apply the manifests to the cluster + run: | + cd starter/backend/k8s + kustomize build | kubectl apply -f - --validate=false \ No newline at end of file diff --git a/.github/workflows/backend-ci.yml b/.github/workflows/backend-ci.yml new file mode 100644 index 00000000..b693737d --- /dev/null +++ b/.github/workflows/backend-ci.yml @@ -0,0 +1,116 @@ +name: Backend CI + +on: + pull_request: + branches: + - main + paths: + - 'starter/backend/**' + workflow_dispatch: + +jobs: + lint: + runs-on: ubuntu-latest + + steps: + - name: Checkout Repository + uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: '3.9' + + - name: Install pipenv + run: | + python -m pip install pipenv + + - name: Install Dependencies + run: | + cd starter/backend + pipenv install + + - name: Install flake8 + run: | + cd starter/backend + pipenv run pip install flake8 + + - name: Lint Code + run: | + cd starter/backend + pipenv run flake8 + + - name: Lint Code + run: | + cd starter/backend + pipenv run lint + + test: + runs-on: ubuntu-latest + + steps: + - name: Checkout Repository + uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: '3.9' + + - name: Install pipenv + run: | + python -m pip install pipenv + + - name: Install Dependencies + run: | + cd starter/backend + pipenv install + + - name: Run Tests + run: | + cd starter/backend + pipenv run test + + build: + runs-on: ubuntu-latest + needs: [lint, test] + + steps: + - name: Checkout Repository + uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: '3.9' + + - name: Install pipenv + run: | + python -m pip install pipenv + + - name: Install Dependencies + run: | + cd starter/backend + pipenv install + + - name: Install flake8 + run: | + cd starter/backend + pipenv run pip install flake8 + + - name: Lint Code + run: | + cd starter/backend + pipenv run flake8 + + # - name: Lint Code (Fail Workflow on Lint Failure) + # run: | + # cd starter/backend + # pipenv run lint-fail + + - name: Build Docker App + run: | + cd starter/backend + docker build -t frontend . + +# Add other steps as needed for your build and test process diff --git a/.github/workflows/frontend-cd.yml b/.github/workflows/frontend-cd.yml new file mode 100644 index 00000000..e545ca7f --- /dev/null +++ b/.github/workflows/frontend-cd.yml @@ -0,0 +1,187 @@ +name: Frontend CD + +on: + push: + branches: + - main + paths: + - 'starter/frontend/**' + workflow_dispatch: + +jobs: + npm: + runs-on: ubuntu-latest + + steps: + - name: Checkout Repository + uses: actions/checkout@v4 + + + - name: Set up Node.js + uses: actions/setup-node@v3 + with: + node-version: '20' + + + - name: Install Dependencies + run: | + cd starter/frontend + npm ci + + + lint: + runs-on: ubuntu-latest + + steps: + - name: Checkout Repository + uses: actions/checkout@v4 + + - name: Set up Node.js + uses: actions/setup-node@v3 + with: + node-version: '20' + + - name: Install Dependencies + run: | + cd starter/frontend + npm install + + - name: Install ESLint + run: | + cd starter/frontend + npm install eslint --save-dev + + - name: Lint Code + run: | + cd starter/frontend + npm run lint + + test: + runs-on: ubuntu-latest + + steps: + - name: Checkout Repository + uses: actions/checkout@v4 + + - name: Set up Node.js + uses: actions/setup-node@v3 + with: + node-version: '20' + + - name: Install Dependencies + run: | + cd starter/frontend + npm ci + + - name: Run Tests + run: | + cd starter/frontend + npm test + + - name: Simulate running tests + run: | + cd starter/frontend + CI=true npm test + + build: + runs-on: ubuntu-latest + needs: [lint, test] # This ensures 'build' only runs if 'lint' and 'test' jobs succeed + + steps: + - name: Checkout Repository + uses: actions/checkout@v4 + + + + - name: Set up Node.js + uses: actions/setup-node@v3 + with: + node-version: '20' + + - name: Install Dependencies + run: | + cd starter/frontend + npm ci + + - name: Configure AWS credentials + uses: aws-actions/configure-aws-credentials@v4 + with: + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + aws-region: us-east-1 + + - name: Login to Amazon ECR + id: login-ecr + uses: aws-actions/amazon-ecr-login@v2 + + - name: Build, tag, and push image to Amazon ECR + env: + ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} + ECR_REPOSITORY: frontend + IMAGE_TAG: ${{ github.sha }} + run: | + aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin 947772818907.dkr.ecr.us-east-1.amazonaws.com + cd starter/frontend/ + docker build --build-arg=REACT_APP_MOVIE_API_URL=http://localhost:5000 -t frontend . + docker tag frontend:latest 947772818907.dkr.ecr.us-east-1.amazonaws.com/frontend:latest + docker push 947772818907.dkr.ecr.us-east-1.amazonaws.com/frontend:latest + + - name: Install kubectl + run: | + curl -sLO https://storage.googleapis.com/kubernetes-release/release/v1.19.9/bin/linux/amd64/kubectl + chmod +x ./kubectl + sudo mv ./kubectl /usr/local/bin/ + + - name: Check kubectl version + run: kubectl version --client + + - name: Display kubectl help + run: kubectl help + + - name: Install Kustomize + run: | + curl -s "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" | bash + sudo mv kustomize /usr/local/bin/ + + + - name: Check Kustomize version + run: kustomize version + + - name: Update AWS CLI + run: | + sudo apt-get install -y awscli + aws --version + + + - name: Add AWS EKS cluster to kubeconfig + run: | + # Specify AWS EKS cluster details + AWS_REGION=us-east-1 + EKS_CLUSTER_NAME=cluster + + # Set the path for the kubeconfig file + KUBECONFIG_PATH=/home/runner/.kube/config + + # Update kubeconfig with AWS EKS cluster + aws eks --region ${AWS_REGION} update-kubeconfig --name ${EKS_CLUSTER_NAME} --kubeconfig $KUBECONFIG_PATH + + + # Display the updated kubeconfig content (optional, for verification) + cat $KUBECONFIG_PATH + + env: + KUBECONFIG: /home/runner/.kube/config + + - name: Check kubectl commands + run: kubectl get pods + + - name: Deploy to EKS + run: | + cd starter/frontend/k8s + kustomize edit set image frontend=947772818907.dkr.ecr.us-east-1.amazonaws.com/frontend:latest + + + - name: Apply the manifests to the cluster + run: | + cd starter/frontend/k8s + kustomize build | kubectl apply -f - --validate=false diff --git a/.github/workflows/frontend-ci.yml b/.github/workflows/frontend-ci.yml new file mode 100644 index 00000000..f5acfe14 --- /dev/null +++ b/.github/workflows/frontend-ci.yml @@ -0,0 +1,113 @@ +name: Frontend CI + +on: + pull_request: + branches: + - main + paths: + - 'starter/frontend/**' + workflow_dispatch: + +jobs: + npm: + runs-on: ubuntu-latest + + steps: + - name: Checkout Repository + uses: actions/checkout@v4 + + - name: Set up Node.js + uses: actions/setup-node@v3 + with: + node-version: '20' + + # - name: Use correct NVM + # run: | + # cd starter/frontend + # nvm use + + - name: Install Dependencies + run: | + cd starter/frontend + npm ci + + + + lint: + runs-on: ubuntu-latest + + steps: + - name: Checkout Repository + uses: actions/checkout@v4 + + - name: Set up Node.js + uses: actions/setup-node@v3 + with: + node-version: '20' + + - name: Install Dependencies + run: | + cd starter/frontend + npm install + + - name: Install ESLint + run: | + cd starter/frontend + npm install eslint --save-dev + + - name: Lint Code + run: | + cd starter/frontend + npm run lint + + test: + runs-on: ubuntu-latest + + steps: + - name: Checkout Repository + uses: actions/checkout@v4 + + - name: Set up Node.js + uses: actions/setup-node@v3 + with: + node-version: '20' + + - name: Install Dependencies + run: | + cd starter/frontend + npm ci + + - name: Run Tests + run: | + cd starter/frontend + npm test + + - name: Simulate running tests + run: | + cd starter/frontend + CI=true npm test + + build: + runs-on: ubuntu-latest + needs: [lint, test] # This ensures 'build' only runs if 'lint' and 'test' jobs succeed + + steps: + - name: Checkout Repository + uses: actions/checkout@v4 + + - name: Set up Node.js + uses: actions/setup-node@v3 + with: + node-version: '20' + + - name: Install Dependencies + run: | + cd starter/frontend + npm ci + + - name: Run NPM Command + run: | + cd starter/frontend + npm run test + + diff --git a/starter/frontend/Dockerfile b/starter/frontend/Dockerfile index 5fe3e2c2..5f87cde9 100644 --- a/starter/frontend/Dockerfile +++ b/starter/frontend/Dockerfile @@ -20,5 +20,5 @@ RUN npm run build # Expose the port used by the React app EXPOSE 3000 -# Start the React app when the container starts -CMD ["npm", "run", "serve"] \ No newline at end of file +# Start the React app when the container starts test +CMD ["npm", "run", "serve"] diff --git a/starter/frontend/config b/starter/frontend/config new file mode 100644 index 00000000..22d74bd8 --- /dev/null +++ b/starter/frontend/config @@ -0,0 +1,40 @@ +apiVersion: v1 +clusters: +- cluster: + certificate-authority-data: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSURCVENDQWUyZ0F3SUJBZ0lJZHBvbDVSczYwc1V3RFFZSktvWklodmNOQVFFTEJRQXdGVEVUTUJFR0ExVUUKQXhNS2EzVmlaWEp1WlhSbGN6QWVGdzB5TkRBeU1qUXdNVFF5TkRkYUZ3MHpOREF5TWpFd01UUTNORGRhTUJVeApFekFSQmdOVkJBTVRDbXQxWW1WeWJtVjBaWE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pJamg1ekRsZjNuZ1NrbmpBMnBrZjlrTDNuCm9GWm4rbTdqbGl5UWVTRUFoVlNIV1ppcnFHcXpqaG9yZ2lPb0dlYVRla0tiSnUzcGNreFA2V2QvVlNjT0xpUEIKUGxHV2FGQVB4bVhGCi0tLS0tRU5EIENFUlRJRklDQVRFLS0tLS0K + server: https://DF43D79A50C08CBF46DDC64893292782.gr7.us-east-1.eks.amazonaws.com + name: arn:aws:eks:us-east-1:947772818907:cluster/cluster +contexts: +- context: + cluster: arn:aws:eks:us-east-1:947772818907:cluster/cluster + user: arn:aws:eks:us-east-1:947772818907:cluster/cluster + name: arn:aws:eks:us-east-1:947772818907:cluster/cluster +current-context: arn:aws:eks:us-east-1:947772818907:cluster/cluster +kind: Config +preferences: {} +users: +- name: github-action-role + user: + exec: + apiVersion: client.authentication.k8s.io/v1alpha1 + args: + - token + - -i + - cluster + command: aws-iam-authenticator + env: null + provideClusterInfo: false +- name: arn:aws:eks:us-east-1:947772818907:cluster/cluster + user: + exec: + apiVersion: client.authentication.k8s.io/v1beta1 + args: + - --region + - us-east-1 + - eks + - get-token + - --cluster-name + - cluster + - --output + - json + command: aws diff --git a/starter/frontend/public/index.html b/starter/frontend/public/index.html index aa069f27..c5700568 100644 --- a/starter/frontend/public/index.html +++ b/starter/frontend/public/index.html @@ -36,7 +36,7 @@ You can add webfonts, meta tags, or analytics to this file. The build step will place the bundled scripts into the tag. - To begin the development, run `npm start` or `yarn start`. + To begin the development test, run `npm start` or `yarn start`. To create a production bundle, use `npm run build` or `yarn build`. -->