kubernetes-resume-challenge #73
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: PHP App CI/CD | |
on: | |
push: | |
branches: [ "master" ] | |
pull_request: | |
branches: [ "master" ] | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- name: PHP testing | |
run: echo "php test" | |
docker: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Build Docker Image | |
uses: docker/build-push-action@v4 | |
with: | |
context: . | |
file: Dockerfile | |
push: false | |
tags: ecom-web:v2 | |
- name: Login to Docker Hub | |
uses: docker/login-action@v2 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- run: | | |
docker tag ecom-web:v2 ${{ secrets.DOCKERHUB_USERNAME }}/ecom-web:v2 | |
docker push ${{ secrets.DOCKERHUB_USERNAME }}/ecom-web:v2 | |
terraform: | |
name: "terraform" | |
runs-on: ubuntu-latest | |
defaults: | |
run: | |
working-directory: ./terraform | |
steps: | |
- name: Checkout Code | |
uses: actions/checkout@v3 | |
- name: Setup Terraform | |
uses: hashicorp/setup-terraform@v1 | |
with: | |
working-directory: ./terraform | |
cli_config_credentials_token: ${{ secrets.TF_API_TOKEN }} | |
- name: Terraform init | |
run: terraform init | |
- name: Terraform Validate | |
run: terraform validate -no-color | |
- name: Terraform Plan | |
run: terraform plan -no-color | |
- name: Terraform Apply | |
run: terraform apply --auto-approve -no-color | |
#- name: Terraform Destroy | |
#run: terraform destroy --auto-approve -no-color | |
kubernetes: | |
needs: terraform | |
name: "deploy to eks" | |
runs-on: ubuntu-latest | |
env: | |
EKS_CLUSTER_NAME: ecommerce-app-cluster | |
AWS_REGION: eu-north-1 | |
defaults: | |
run: | |
working-directory: ./kubernetes | |
steps: | |
- name: Checkout Code | |
uses: actions/checkout@v3 | |
- name: Configure AWS credentials | |
uses: aws-actions/configure-aws-credentials@v1 | |
with: | |
working-directory: ./kubernetes | |
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
aws-region: ${{env.AWS_REGION}} | |
- name: Update kube config | |
run: aws eks update-kubeconfig --name $EKS_CLUSTER_NAME --region $AWS_REGION | |
#- name: Create secret to pull image | |
#run: kubectl create secret docker-registry regcred --docker-server=docker.io --docker-username=${{ secrets.DOCKERHUB_USERNAME }} --docker-password=${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Deploy To EKS | |
run: | | |
kubectl apply -f mariadb-secret.yml | |
kubectl apply -f mariadb-configmap.yml | |
kubectl apply -f mariadb.yml | |
kubectl apply -f mariadb-svc.yml | |
kubectl apply -f ecom-web-configmap.yml | |
kubectl apply -f ecom-web-config.yml | |
kubectl apply -f ecom-web.yml | |
kubectl apply -f ecom-web-svc.yml |