diff --git a/deploy/production/postgres.yaml b/deploy/production/postgres.yaml new file mode 100644 index 00000000..ca64acf1 --- /dev/null +++ b/deploy/production/postgres.yaml @@ -0,0 +1,71 @@ +--- +apiVersion: v1 +kind: Service +metadata: + name: postgres-production-svc + namespace: sigs-production + labels: + app: postgres +spec: + ports: + - port: 5432 + selector: + app: postgres + tier: database +--- +apiVersion: apps/v1beta2 +kind: Deployment +metadata: + name: postgres-sigs-production + namespace: sigs-production + labels: + app: postgres +spec: + replicas: 1 + selector: + matchLabels: + app: postgres + tier: database + template: + metadata: + name: postgres + labels: + app: postgres + tier: database + spec: + volumes: + - name: postgres-pv + persistentVolumeClaim: + claimName: postgres-production-pvc + containers: + - name: postgres + image: postgres:11.2 + env: + - name: POSTGRES_USER + valueFrom: + secretKeyRef: + name: "sigs-production-secrets" + key: "db-user" + - name: POSTGRES_PASSWORD + valueFrom: + secretKeyRef: + name: "sigs-production-secrets" + key: "db-user-pass" + - name: POSTGRES_PORT + value: "5432" + - name: POSTGRES_DB + value: "SIGS_production" + ports: + - containerPort: 5432 +--- +kind: PersistentVolumeClaim +apiVersion: v1 +metadata: + name: postgres-production-pvc + namespace: sigs-production +spec: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 8Gi diff --git a/deploy/production/sigs.yaml b/deploy/production/sigs.yaml new file mode 100644 index 00000000..96b4fb3c --- /dev/null +++ b/deploy/production/sigs.yaml @@ -0,0 +1,88 @@ +--- +kind: Ingress +apiVersion: extensions/v1beta1 +metadata: + name: sigs-ingress + namespace: sigs-production + labels: + app: sigs-production + annotations: + nginx.ingress.kubernetes.io/ssl-redirect: "true" + certmanager.k8s.io/cluster-issuer: letsencrypt-prod +spec: + rules: + - host: sigs.lappis.rocks + http: + paths: + - backend: + serviceName: sigs-production-svc + servicePort: 80 + tls: + - hosts: + - sigs.lappis.rocks + secretName: sigs-production-letsencrypt-prod-crt +--- +apiVersion: v1 +kind: Service +metadata: + name: sigs-production-svc + namespace: sigs-production + labels: + app: sigs-production +spec: + ports: + - port: 80 + targetPort: 3000 + protocol: TCP + name: http + selector: + app: sigs-production +--- +kind: Deployment +apiVersion: apps/v1 +metadata: + name: sigs-deployment + namespace: sigs-production + labels: + app: sigs-production +spec: + selector: + matchLabels: + app: sigs-production + replicas: 1 + template: + metadata: + labels: + app: sigs-production + spec: + containers: + - name: sigs-production + image: projetosigs/sigs-gces:stable + imagePullPolicy: Always + ports: + - containerPort: 3000 + protocol: TCP + env: + - name: SECRET_KEY_BASE + valueFrom: + secretKeyRef: + name: "sigs-production-secrets" + key: "app-secret-key" + - name: POSTGRES_USER + valueFrom: + secretKeyRef: + name: "sigs-production-secrets" + key: "db-user" + - name: POSTGRES_PASSWORD + valueFrom: + secretKeyRef: + name: "sigs-production-secrets" + key: "db-user-pass" + - name: POSTGRES_PORT + value: "5432" + - name: POSTGRES_DB + value: "SIGS_production" + - name: POSTGRES_HOST + value: postgres-production-svc + - name: SIGS_DOMAIN + value: sigs.lappis.rocks \ No newline at end of file diff --git a/deploy/staging-deploy.sh b/deploy/staging-deploy.sh old mode 100755 new mode 100644 diff --git a/deploy/staging/postgres.yaml b/deploy/staging/postgres.yaml new file mode 100644 index 00000000..4cf7df20 --- /dev/null +++ b/deploy/staging/postgres.yaml @@ -0,0 +1,71 @@ +--- +apiVersion: v1 +kind: Service +metadata: + name: postgres-staging-svc + namespace: sigs-staging + labels: + app: postgres +spec: + ports: + - port: 5432 + selector: + app: postgres + tier: database +--- +apiVersion: apps/v1beta2 +kind: Deployment +metadata: + name: postgres-sigs-staging + namespace: sigs-staging + labels: + app: postgres +spec: + replicas: 1 + selector: + matchLabels: + app: postgres + tier: database + template: + metadata: + name: postgres + labels: + app: postgres + tier: database + spec: + volumes: + - name: postgres-pv + persistentVolumeClaim: + claimName: postgres-staging-pvc + containers: + - name: postgres + image: postgres:11.2 + env: + - name: POSTGRES_USER + valueFrom: + secretKeyRef: + name: "sigs-staging-secrets" + key: "db-user" + - name: POSTGRES_PASSWORD + valueFrom: + secretKeyRef: + name: "sigs-staging-secrets" + key: "db-user-pass" + - name: POSTGRES_PORT + value: "5432" + - name: POSTGRES_DB + value: "SIGS_production" + ports: + - containerPort: 5432 +--- +kind: PersistentVolumeClaim +apiVersion: v1 +metadata: + name: postgres-staging-pvc + namespace: sigs-staging +spec: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 8Gi diff --git a/deploy/staging/sigs.yaml b/deploy/staging/sigs.yaml new file mode 100644 index 00000000..6832d8b9 --- /dev/null +++ b/deploy/staging/sigs.yaml @@ -0,0 +1,88 @@ +--- +kind: Ingress +apiVersion: extensions/v1beta1 +metadata: + name: sigs-ingress + namespace: sigs-staging + labels: + app: sigs-staging + annotations: + nginx.ingress.kubernetes.io/ssl-redirect: "true" + certmanager.k8s.io/cluster-issuer: letsencrypt-prod +spec: + rules: + - host: sigs.dev.lappis.rocks + http: + paths: + - backend: + serviceName: sigs-staging-svc + servicePort: 80 + tls: + - hosts: + - sigs.dev.lappis.rocks + secretName: sigs-staging-letsencrypt-prod-crt +--- +apiVersion: v1 +kind: Service +metadata: + name: sigs-staging-svc + namespace: sigs-staging + labels: + app: sigs-staging +spec: + ports: + - port: 80 + targetPort: 3000 + protocol: TCP + name: http + selector: + app: sigs-staging +--- +kind: Deployment +apiVersion: apps/v1 +metadata: + name: sigs-deployment + namespace: sigs-staging + labels: + app: sigs-staging +spec: + selector: + matchLabels: + app: sigs-staging + replicas: 1 + template: + metadata: + labels: + app: sigs-staging + spec: + containers: + - name: sigs-staging + image: projetosigs/sigs-gces:latest + imagePullPolicy: Always + ports: + - containerPort: 3000 + protocol: TCP + env: + - name: SECRET_KEY_BASE + valueFrom: + secretKeyRef: + name: "sigs-staging-secrets" + key: "app-secret-key" + - name: POSTGRES_USER + valueFrom: + secretKeyRef: + name: "sigs-staging-secrets" + key: "db-user" + - name: POSTGRES_PASSWORD + valueFrom: + secretKeyRef: + name: "sigs-staging-secrets" + key: "db-user-pass" + - name: POSTGRES_PORT + value: "5432" + - name: POSTGRES_DB + value: "SIGS_production" + - name: POSTGRES_HOST + value: postgres-staging-svc + - name: SIGS_DOMAIN + value: sigs.lappis.rocks \ No newline at end of file diff --git a/docker/dev/entrypoint.sh b/docker/dev/entrypoint.sh old mode 100755 new mode 100644 index 49f37a96..3d680fb2 --- a/docker/dev/entrypoint.sh +++ b/docker/dev/entrypoint.sh @@ -2,14 +2,20 @@ function_postgres_ready() { ruby << END -require 'pg' -begin - PG.connect(dbname: "$POSTGRES_DB", user: "$POSTGRES_USER", password: "$POSTGRES_PASSWORD", host: "postgres") -rescue - exit -1 -else - exit 0 -end + require 'pg' + puts 'Version of libpg: ' + PG.library_version.to_s + begin + con = PG.connect( dbname: "$POSTGRES_DB", + user: "$POSTGRES_USER", + host: "$POSTGRES_HOST", + password: "$POSTGRES_PASSWORD") + rescue PG::Error => e + puts e.message + exit -1 + ensure + con.close if con + exit 0 + end END } diff --git a/docker/prod/entrypoint.sh b/docker/prod/entrypoint.sh old mode 100755 new mode 100644 index 1342dae3..ca96f94a --- a/docker/prod/entrypoint.sh +++ b/docker/prod/entrypoint.sh @@ -2,14 +2,20 @@ function_postgres_ready() { ruby << END -require 'pg' -begin - PG.connect(dbname: "$POSTGRES_DB", user: "$POSTGRES_USER", password: "$POSTGRES_PASSWORD", host: "postgres") -rescue - exit -1 -else - exit 0 -end + require 'pg' + puts 'Version of libpg: ' + PG.library_version.to_s + begin + con = PG.connect( dbname: "$POSTGRES_DB", + user: "$POSTGRES_USER", + host: "$POSTGRES_HOST", + password: "$POSTGRES_PASSWORD") + rescue PG::Error => e + puts e.message + exit -1 + ensure + con.close if con + exit 0 + end END } @@ -32,5 +38,5 @@ if [ -f $pidfile ]; then rm $pidfile fi -#bundle exec rails s -p 3000 -b 0.0.0.0 -e production -bundle exec puma -C config/puma.rb \ No newline at end of file +bundle exec rails s -p 3000 -b 0.0.0.0 -e production +#bundle exec puma -C config/puma.rb \ No newline at end of file