Skip to content

Commit

Permalink
Merge pull request #65 from islamic-network/nunit
Browse files Browse the repository at this point in the history
Nunit
  • Loading branch information
meezaan authored Mar 25, 2023
2 parents 6b00a96 + 8cb6865 commit f874fec
Show file tree
Hide file tree
Showing 14 changed files with 1,042 additions and 199 deletions.
56 changes: 46 additions & 10 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ executors:
environment:
IMAGE_NAME: ghcr.io/islamic-network/api.aladhan.com
QUAYIO_IMAGE_NAME: quay.io/islamic-network/api.aladhan.com
DOCKERHUB_IMAGE_NAME: islamicnetwork/api.aladhan.com
docker:
- image: circleci/buildpack-deps:stretch
php74:
Expand Down Expand Up @@ -55,20 +56,55 @@ jobs:
name: Build Production Docker image
command: |
echo "$GITHUB_TOKEN" | docker login ghcr.io --username "$DOCKERHUB_USERNAME" --password-stdin
docker build -t $IMAGE_NAME:latest .
echo "Pushing latest tag to Docker Hub..."
echo "$DOCKERHUB_PASSWORD" | docker login --username "$DOCKERHUB_USERNAME" --password-stdin
echo "$QUAYIO_PASSWORD" | docker login quay.io --username "$QUAYIO_USERNAME" --password-stdin
echo "Default registry: GHCR"
echo "Build latest Unit Image"
docker build -f Dockerfile.nunit . -t $IMAGE_NAME:unit-latest
echo "Build latest Apache Image"
docker build -f Dockerfile.apache . -t $IMAGE_NAME:apache-latest
echo "Mark Unit as the default latest"
docker tag $IMAGE_NAME:unit-latest $IMAGE_NAME:latest
echo "Pushing latest tag to GHCR..."
docker push $IMAGE_NAME:latest
docker push $IMAGE_NAME:unit-latest
docker push $IMAGE_NAME:apache-latest
echo "Get Image tag"
IMAGE_TAG=${CIRCLE_TAG}
echo "Pushing tag $IMAGE_TAG to Docker Hub..."
docker tag $IMAGE_NAME:latest $IMAGE_NAME:$IMAGE_TAG
docker push $IMAGE_NAME:$IMAGE_TAG
echo "$QUAYIO_PASSWORD" | docker login quay.io --username "$QUAYIO_USERNAME" --password-stdin
echo "Pushing tag $IMAGE_TAG to GHCR for Unit and Apache..."
docker tag $IMAGE_NAME:unit-latest $IMAGE_NAME:unit-$IMAGE_TAG
docker tag $IMAGE_NAME:apache-latest $IMAGE_NAME:apache-$IMAGE_TAG
docker push $IMAGE_NAME:unit-$IMAGE_TAG
docker push $IMAGE_NAME:apache-$IMAGE_TAG
echo "Push all images to Quay.io"
docker tag $IMAGE_NAME:latest $QUAYIO_IMAGE_NAME:latest
echo "Pushing latest tag to quay.io..."
docker tag $IMAGE_NAME:unit-latest $QUAYIO_IMAGE_NAME:unit-latest
docker tag $IMAGE_NAME:apache-latest $QUAYIO_IMAGE_NAME:apache-latest
docker tag $IMAGE_NAME:unit-latest $QUAYIO_IMAGE_NAME:unit-$IMAGE_TAG
docker tag $IMAGE_NAME:apache-latest $QUAYIO_IMAGE_NAME:apache-$IMAGE_TAG
docker push $QUAYIO_IMAGE_NAME:latest
docker tag $IMAGE_NAME:latest $QUAYIO_IMAGE_NAME:$IMAGE_TAG
echo "Pushing tag $IMAGE_TAG to quay.io..."
docker push $QUAYIO_IMAGE_NAME:$IMAGE_TAG
docker push $QUAYIO_IMAGE_NAME:unit-latest
docker push $QUAYIO_IMAGE_NAME:apache-latest
docker push $QUAYIO_IMAGE_NAME:unit-$IMAGE_TAG
docker push $QUAYIO_IMAGE_NAME:apache-$IMAGE_TAG
echo "Push all images to Docker Hub"
docker tag $IMAGE_NAME:latest $DOCKERHUB_IMAGE_NAME:latest
docker tag $IMAGE_NAME:unit-latest $DOCKERHUB_IMAGE_NAME:unit-latest
docker tag $IMAGE_NAME:apache-latest $DOCKERHUB_IMAGE_NAME:apache-latest
docker tag $IMAGE_NAME:unit-latest $DOCKERHUB_IMAGE_NAME:unit-$IMAGE_TAG
docker tag $IMAGE_NAME:apache-latest $DOCKERHUB_IMAGE_NAME:apache-$IMAGE_TAG
docker push $DOCKERHUB_IMAGE_NAME:latest
docker push $DOCKERHUB_IMAGE_NAME:unit-latest
docker push $DOCKERHUB_IMAGE_NAME:apache-latest
docker push $DOCKERHUB_IMAGE_NAME:unit-$IMAGE_TAG
docker push $DOCKERHUB_IMAGE_NAME:apache-$IMAGE_TAG
deploy-docker-tag-dallas:
executor: docker-publisher
Expand Down
287 changes: 287 additions & 0 deletions .k8s/apache-manifests/manifest-dallas.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,287 @@
# Deployment
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: aladhan-com-api
namespace: aladhan-com
spec:
replicas: 3
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 2
maxUnavailable: 0
selector:
matchLabels:
app: aladhan-com-api
template:
metadata:
labels:
app: aladhan-com-api
spec:
containers:
- name: apache-exporter-sidecar
image: lusotycoon/apache-exporter
args:
- '--scrape_uri=http://localhost:8080/server-status?auto'
ports:
- containerPort: 9117
protocol: TCP
resources:
requests:
cpu: 50m
memory: 32Mi
limits:
cpu: 100m
memory: 128Mi
- name: aladhan-com-api
image: ghcr.io/islamic-network/api.aladhan.com:$COMMIT_TAG
env:
- name: MEMCACHED_HOST
value: "aladhan-com-api-memcached"
- name: MEMCACHED_PORT
value: "11211"
- name: X7X_API_KEY
valueFrom:
secretKeyRef:
name: aladhan-com-api-7x-creds
key: apikey
livenessProbe:
httpGet:
path: /status
port: 8080
initialDelaySeconds: 3
periodSeconds: 7
timeoutSeconds: 7
failureThreshold: 7
startupProbe:
httpGet:
path: /status
port: 8080
periodSeconds: 3
failureThreshold: 3
resources:
requests:
cpu: "400m"
memory: 250Mi
limits:
cpu: "750m"
memory: 600Mi
ports:
- containerPort: 8080
protocol: TCP
---
# HPA
apiVersion: autoscaling/v1
kind: HorizontalPodAutoscaler
metadata:
name: aladhan-com-api
namespace: aladhan-com
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: aladhan-com-api
minReplicas: 3
maxReplicas: 30
targetCPUUtilizationPercentage: 75
---
# Memcached
apiVersion: apps/v1
kind: Deployment
metadata:
name: aladhan-com-api-memcached
namespace: aladhan-com
spec:
replicas: 1
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 1
maxUnavailable: 1
selector:
matchLabels:
app: aladhan-com-api-memcached
template:
metadata:
labels:
app: aladhan-com-api-memcached
spec:
nodeSelector:
lke.linode.com/pool-id: "130436"
containers:
- name: aladhan-com-api-memcached
image: memcached:1.6
args:
- "memcached"
- "-m"
- "256"
resources:
requests:
memory: 288Mi
limits:
memory: 288Mi
ports:
- containerPort: 11211
protocol: TCP
---
# Service
apiVersion: v1
kind: Service
metadata:
name: aladhan-com-api
namespace: aladhan-com
annotations:
konghq.com/plugins: rate-limiting-aladhan-api, proxy-cache-redis-aladhan-api
spec:
ports:
- port: 80
targetPort: 8080
selector:
app: aladhan-com-api
---
apiVersion: v1
kind: Service
metadata:
name: aladhan-com-api-memcached
namespace: aladhan-com
spec:
ports:
- port: 11211
targetPort: 11211
selector:
app: aladhan-com-api-memcached
---
apiVersion: v1
kind: Service
metadata:
name: aladhan-com-api-metrics
namespace: aladhan-com
labels:
name: aladhan-com-api-metrics
spec:
type: ClusterIP
selector:
app: aladhan-com-api
ports:
- name: metrics
port: 9117
targetPort: 9117
---
apiVersion: configuration.konghq.com/v1
kind: KongPlugin
metadata:
name: rate-limiting-aladhan-api
namespace: aladhan-com
config:
second: 24
policy: redis
redis_host: redis-ratelimit-master
redis_port: 6379
limit_by: ip
plugin: rate-limiting
---
apiVersion: configuration.konghq.com/v1
kind: KongPlugin
metadata:
name: proxy-cache-redis-aladhan-api
namespace: aladhan-com
config:
response_code:
- 200
- 400
- 301
request_method:
- GET
- HEAD
content_type:
- application/json
cache_ttl: 3600
cache_control: false
allow_force_cache_header: false
storage_ttl: 3600
redis_port: 6379
redis_host: redis-cache-aladhan-master
plugin: proxy-cache-redis
---
apiVersion: configuration.konghq.com/v1
kind: KongPlugin
metadata:
name: bot-detection-aladhan-api
namespace: aladhan-com
plugin: bot-detection
---
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
name: aladhan-com-api-metrics
namespace: monitoring
labels:
release: lke-monitor
spec:
selector:
matchLabels:
name: aladhan-com-api-metrics
namespaceSelector:
any: true
endpoints:
- port: "metrics"
interval: 30s
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: aladhan-com-api-ingress
namespace: aladhan-com
annotations:
kubernetes.io/tls-acme: "true"
cert-manager.io/cluster-issuer: letsencrypt-prod
kubernetes.io/ingress.class: kong
spec:
tls:
- hosts:
- "api.aladhan.com"
- "dallas.api.aladhan.com"
secretName: "aladhan-com-api-tls"
rules:
- host: api.aladhan.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: aladhan-com-api
port:
number: 80
- host: dallas.api.aladhan.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: aladhan-com-api
port:
number: 80
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: aladhan-com-geo-ingress
namespace: aladhan-com
annotations:
kubernetes.io/ingress.class: kong
spec:
rules:
- host: geo.aladhan.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: aladhan-com-api
port:
number: 80
Loading

0 comments on commit f874fec

Please sign in to comment.