Skip to content

Commit

Permalink
fulcimen-demo
Browse files Browse the repository at this point in the history
  • Loading branch information
gkostin1966 committed Jun 9, 2021
1 parent 033f689 commit edd744f
Show file tree
Hide file tree
Showing 21 changed files with 413 additions and 4 deletions.
13 changes: 13 additions & 0 deletions .github/manifests/fulcimen-load-balancer-service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: v1
kind: Service
metadata:
labels:
app: fulcimen
name: web
spec:
selector:
app: fulcimen
ports:
- port: 80
targetPort: 3000
type: LoadBalancer
21 changes: 21 additions & 0 deletions .github/manifests/fulcimen-rails-deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: fulcimen
name: rails
spec:
replicas: 1
selector:
matchLabels:
app: fulcimen
template:
metadata:
labels:
app: fulcimen
spec:
containers:
- image: docker.pkg.github.com/mlibrary/heliotropium/fulcimen:d56befee705bacbb6306f8bd8bea597f31608636
name: heliotropium
ports:
- containerPort: 3000
19 changes: 19 additions & 0 deletions .github/workflows/delete-workflow-runs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: delete-workflow-runs
on:
workflow_dispatch:
inputs:
days:
description: 'Number of days.'
required: true
default: 90

jobs:
del_runs:
runs-on: ubuntu-latest
steps:
- name: Delete workflow runs
uses: Mattraks/delete-workflow-runs@main
with:
# token: ${{ secrets.AUTH_PAT }}
# repository: ${{ github.repository }}
retain_days: ${{ github.event.inputs.days }}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: deploy-branch-to-testing
name: deploy-branch-image-to-testing

on: workflow_dispatch

Expand All @@ -25,8 +25,13 @@ jobs:
kubectl config set-credentials default --token=`echo ${{ secrets.TOKEN_BASE64 }} | base64 -d`
kubectl config set-context default --cluster=cluster --user=default --namespace=`echo ${{ secrets.NAMESPACE_BASE64 }} | base64 -d`
kubectl config use-context default
- name: Deploy
run: |
kubectl config view
kubectl config current-context
# kubectl set image deployment web web=docker.pkg.github.com/mlibrary/patron_account/patron_account:${{ steps.tag_check.outputs.tag }}
# - name: Checkout
# uses: actions/checkout@v2
- name: Deploy
run: |
# kubectl apply -f ./.github/manifests/fulcimen-rails-deployment.yaml
# kubectl apply -f ./.github/manifests/fulcimen-load-balancer-service.yaml
kubectl set image deployment/rails heliotropium=docker.pkg.github.com/mlibrary/heliotropium/fulcimen:d56befee705bacbb6306f8bd8bea597f31608636
# kubectl expose deployment fulcimen --type="LoadBalancer" --target-port=3000 --port=80 --name=web
62 changes: 62 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#Start with Ruby 2.7.2 Image
FROM ruby:2.7.2

#Set up variables for creating a user to run the app in the container
ARG UNAME=app
ARG UID=1000
ARG GID=1000

#This is so rails can install properly
RUN apt-get update -yqq && apt-get install -yqq --no-install-recommends \
apt-transport-https

#Download node at the preferred version; Download Yarn
RUN curl -sL https://deb.nodesource.com/setup_12.x | bash -
RUN curl https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
RUN echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list

# Install Node and Vim. Vim is optional, but can be nice to be able to look
# to be able to actually look at files in the container.
RUN apt-get update -yqq && apt-get install -yqq --no-install-recommends \
nodejs \
yarn \
vim

#So we can bundle install
RUN gem install bundler:2.1.4

#Create the group for the user
RUN groupadd -g ${GID} -o ${UNAME}

#Create the User and assign /app as its home directory
RUN useradd -m -d /app -u ${UID} -g ${GID} -o -s /bin/bash ${UNAME}


#Create a /gems directory; Putting it here makes it easer to create a gems volume.
RUN mkdir -p /gems && chown ${UID}:${GID} /gems

#Change to that User; Waited until this step because the app user doesn't
#have the authority to great the /gems directory that was done above.
USER $UNAME

#Tell bundler to use the /gems directory
ENV BUNDLE_PATH /gems

#Copy the Gemfile and Gemfile.lock from the Host machine into the /app directory;
COPY --chown=${UID}:${GID} Gemfile* /app/

#cd to app
WORKDIR /app

#Install the Gems. Notice that this is done when only Gemfile and
#Gemfile.lock are in the /app directory
RUN bundle install

#Copy all of the files in the current Host directory into /app
COPY --chown=${UID}:${GID} . /app

#Set up Placeholder Environment Variables; These will be overwritten
#by Docker Compose and in production

#Run the application
CMD ["bin/rails", "s", "-b", "0.0.0.0"]
58 changes: 58 additions & 0 deletions Dockerfile.noah
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
FROM ruby:2.6
ARG UNAME=app
ARG UID=1000
ARG GID=1000
ARG APP_HOME=/app
ARG GEM_HOME=/gems

# Adapted from https://medium.com/hackernoon/preventing-race-conditions-in-docker-781854121ed3
ENV DOCKERIZE_VERSION=v0.5.0
RUN wget -O - \
https://github.com/jwilder/dockerize/releases/download/$DOCKERIZE_VERSION/dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz \
| tar -C /usr/local/bin -xzvf -

RUN wget -q -O- https://dl.yarnpkg.com/debian/pubkey.gpg | \
apt-key add - && \
echo "deb https://dl.yarnpkg.com/debian/ stable main" > \
/etc/apt/sources.list.d/yarn.list && \
apt-get update && \
apt-get install -yqq --no-install-recommends \
apt-transport-https \
nodejs \
yarn && \
rm -rf /var/lib/apt/lists/* /usr/share/doc /usr/share/locale /usr/share/man
RUN gem install bundler

RUN groupadd -g $GID -o $UNAME
RUN useradd -m -d /home/app -u $UID -g $GID -o -s /bin/bash $UNAME
RUN mkdir -p $APP_HOME && chown $UID:$GID $APP_HOME
RUN mkdir -p $GEM_HOME && chown $UID:$GID $GEM_HOME

ENV BUNDLE_GEMFILE=${APP_HOME}/Gemfile
ENV BUNDLE_JOBS=2
ENV BUNDLE_PATH=${GEM_HOME}
ENV DB_VENDOR=mysql
ENV DB_ADAPTER=mysql2
ENV MYSQL_PORT=3306
ENV MYSQL_HOST=db
ENV MYSQL_USER=helio
ENV MYSQL_PASSWORD=helio
ENV MYSQL_DATABASE=helio
ENV RAILS_ENV=development

RUN mkdir -p ${APP_HOME} ${BUNDLE_PATH}
WORKDIR ${APP_HOME}

USER $UNAME
COPY --chown=$UID:$GID Gemfile* ${APP_HOME}/
RUN bundle install

# Note that docker-compose.yml mounts /app/node_modules like the gem cache
COPY --chown=$UID:$GID package.json yarn.lock ${APP_HOME}/
RUN yarn install --check-files

COPY --chown=$UID:$GID . ${APP_HOME}

CMD dockerize -wait tcp://${MYSQL_HOST}:${MYSQL_PORT} -timeout 5m && \
bundle exec rake db:migrate && \
bundle exec rails server --binding 0.0.0.0 --port 3000
7 changes: 7 additions & 0 deletions k8s/fulcimen-demo/apply.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash
kubectl apply -f fulcimen-demo-namespace.yaml
#kubectl apply -f fulcimen-demo-resource-quota.yaml
kubectl apply -f mysql-external-name-service.yaml
kubectl apply -f mysql-client-alpine-pod.yaml
kubectl apply -f fulcimen-deployment.yaml
kubectl apply -f fulcimen-node-port-service.yaml
7 changes: 7 additions & 0 deletions k8s/fulcimen-demo/delete.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash
kubectl delete -f fulcimen-node-port-service.yaml
kubectl delete -f fulcimen-deployment.yaml
kubectl delete -f mysql-client-alpine-pod.yaml
kubectl delete -f mysql-external-name-service.yaml
#kubectl delete -f fulcimen-demo-resource-quota.yaml
kubectl delete -f fulcimen-demo-namespace.yaml
4 changes: 4 additions & 0 deletions k8s/fulcimen-demo/fulcimen-demo-namespace.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
apiVersion: v1
kind: Namespace
metadata:
name: fulcimen-demo
11 changes: 11 additions & 0 deletions k8s/fulcimen-demo/fulcimen-demo-resource-quota.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: v1
kind: ResourceQuota
metadata:
name: fulcimen-demo
namespace: fulcimen-demo
spec:
hard:
requests.cpu: "4"
requests.memory: 8Gi
limits.cpu: "8"
limits.memory: 16Gi
34 changes: 34 additions & 0 deletions k8s/fulcimen-demo/fulcimen-deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: fulcimen
name: fulcimen-deployment
namespace: fulcimen-demo
spec:
replicas: 1
selector:
matchLabels:
app: fulcimen
template:
metadata:
annotations:
imageregistry: "https://hub.docker.com/"
labels:
app: fulcimen
spec:
containers:
- name: heliotropium
image: gkostin1966/heliotropium:0.0.1
env:
- name: DATABASE_URL
value: "mysql2://mysql/heliotropium_development"
ports:
- containerPort: 3000
# resources:
# limits:
# memory: "2Gi"
# cpu: "1000m"
# requests:
# memory: "1Gi"
# cpu: "500m"
16 changes: 16 additions & 0 deletions k8s/fulcimen-demo/fulcimen-node-port-service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
apiVersion: v1
kind: Service
metadata:
labels:
app: fulcimen
name: fulcimen-node-port
namespace: fulcimen-demo
spec:
ports:
- nodePort: 30000 # externally exposed port e.g. localhost:30080
port: 3000 # static node port (virtual or physical machine) e.g. docker-desktop
protocol: TCP
targetPort: 3000 # container port e.g. deployment/fulcimen
selector:
app: fulcimen
type: NodePort
51 changes: 51 additions & 0 deletions k8s/fulcimen-demo/mysql-client-alpine-pod.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
apiVersion: v1
kind: Pod
metadata:
labels:
app: fulcimen
name: mysql-client
namespace: fulcimen-demo
spec:
containers:
- image: alpine
name: alpine
command: ["sh"]
args: ["-c", "sleep 100000"]
# Sleep long enough to use for host MySQL connection testing
# kubectl -c alpine -it exec mysql-client --namespace=fulcimen-demo -- sh
# Use ping to test connection to host
# ping mysql
# Install mysql-client to test connection to host MySQL
# apk --no-cache add mysql-client
# mysql -h mysql -u root
# Welcome to the MariaDB monitor. Commands end with ; or \g.
# Your MySQL connection id is 19
# Server version: 8.0.23 Homebrew
#
# Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
#
# Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
# MySQL [(none)]> show databases;
# +--------------------------------+
# | Database |
# +--------------------------------+
# | gkostin_heliotrope_development |
# | gkostin_heliotrope_test |
# | heliotrope_development |
# | heliotrope_test |
# | heliotropium_development |
# | heliotropium_test |
# | information_schema |
# | mysql |
# | performance_schema |
# | swapmeet_development |
# | swapmeet_test |
# | sys |
# | thyrax_development |
# | thyrax_test |
# +--------------------------------+
# 14 rows in set (0.004 sec)
#
# MySQL [(none)]> quit
# Bye
# exit
17 changes: 17 additions & 0 deletions k8s/fulcimen-demo/mysql-external-name-service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
apiVersion: v1
kind: Service
metadata:
labels:
app: fulcimen
name: mysql
namespace: fulcimen-demo
spec:
type: ExternalName
externalName: host.docker.internal
# Commented out line 4 and added line 5 to /usr/local/etc/my.cnf
# 1 # Default Homebrew MySQL server config
# 2 [mysqld]
# 3 # Only allow connections from localhost
# 4 # bind-address = 127.0.0.1
# 5 bind-address = 0.0.0.0
# So MySQL will accept external connections
12 changes: 12 additions & 0 deletions k8s/fulcimen-staging/mysql-ep.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: v1
kind: Endpoints
metadata:
labels:
app: heliotropium
name: mysql-ep
namespace: heliotropium-demo
subsets:
- addresses:
- ip: 192.0.2.42
ports:
- port: 3306
5 changes: 5 additions & 0 deletions k8s/nginx-demo/apply.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash
kubectl apply -f nginx-demo-namespace.yaml
kubectl apply -f nginx-demo-resource-quota.yaml
kubectl apply -f nginx-deployment.yaml
kubectl apply -f nginx-node-port-service.yaml
5 changes: 5 additions & 0 deletions k8s/nginx-demo/delete.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash
kubectl delete -f nginx-node-port-service.yaml
kubectl delete -f nginx-deployment.yaml
kubectl delete -f nginx-demo-resource-quota.yaml
kubectl delete -f nginx-demo-namespace.yaml

0 comments on commit edd744f

Please sign in to comment.