From 3d7693fd37973ed0cd18a6b5ca091d984abea946 Mon Sep 17 00:00:00 2001 From: hawkinswinja Date: Tue, 30 Apr 2024 19:01:54 +0300 Subject: [PATCH 1/2] feat: added docker implementation for the app --- .dockerignore | 23 +++++++++++++++++++++++ Dockerfile | 15 +++++++++++++++ config/database.yml | 19 +++++++++++-------- 3 files changed, 49 insertions(+), 8 deletions(-) create mode 100644 .dockerignore create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..67eb20df --- /dev/null +++ b/.dockerignore @@ -0,0 +1,23 @@ +# Ignore bundler config. +/.bundle + +# Ignore all logfiles and tempfiles. +/log/* +/tmp/* +!/log/.keep +!/tmp/.keep + +/node_modules +/yarn-error.log + +.byebug_history + +/public/packs +/public/packs-test +/node_modules +/yarn-error.log +yarn-debug.log* +.yarn-integrity + +/.* +README.md diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..13067735 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,15 @@ +FROM ruby:latest + +WORKDIR /app + +RUN curl -fsSL https://deb.nodesource.com/setup_22.x | bash - && \ + apt-get install -y nodejs && npm -g install yarn && yarn -v + +COPY Gemfile* . +RUN bundle install +COPY package.json . +RUN yarn install +EXPOSE 3000 +COPY . . +# ENTRYPOINT [ "bash" ] +CMD ["rails", "server", "-b", "0.0.0.0"] \ No newline at end of file diff --git a/config/database.yml b/config/database.yml index 4b76d2b3..5e82cd28 100644 --- a/config/database.yml +++ b/config/database.yml @@ -20,24 +20,26 @@ default: &default # For details on connection pooling, see Rails configuration guide # http://guides.rubyonrails.org/configuring.html#database-pooling pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> + username: <%= ENV['POSTGRES_USER'] %> + password: <%= ENV['POSTGRES_PASSWORD'] %> + host: <%= ENV['POSTGRES_HOST'] %> development: <<: *default - database: open-flights_development - + database: <%= ENV['POSTGRES_DB'] %> # The specified database role being used to connect to postgres. # To create additional roles in postgres see `$ createuser --help`. # When left blank, postgres will use the default role. This is # the same name as the operating system user that initialized the database. - #username: open-flights + # username: ruby # The password associated with the postgres role (username). - #password: + # password: ruby # Connect on a TCP socket. Omitted by default since the client uses a # domain socket that doesn't need configuration. Windows does not have # domain sockets, so uncomment these lines. - #host: localhost + # host: 172.17.0.2 # The TCP port the server listens on. Defaults to 5432. # If your server runs on a different port number, change accordingly. @@ -80,6 +82,7 @@ test: # production: <<: *default - database: open-flights_production - username: open-flights - password: <%= ENV['OPEN-FLIGHTS_DATABASE_PASSWORD'] %> + database: <%= ENV['POSTGRES_DB'] %> + username: <%= ENV['POSTGRES_USER'] %> + password: <%= ENV['POSTGRES_PASSWORD'] %> + host: <%= ENV['POSTGRES_HOST'] %> From 100612b08c71dd42bddf3bfa1e8a847e17c93e57 Mon Sep 17 00:00:00 2001 From: hawkinswinja Date: Thu, 2 May 2024 00:25:16 +0300 Subject: [PATCH 2/2] add: tekton ci pipline configuration --- .gitignore | 1 + .tekton/docker-secret.yaml | 8 +++++++ .tekton/open-flights-pipeline.yaml | 38 ++++++++++++++++++++++++++++++ .tekton/pipeline-run.yaml | 27 +++++++++++++++++++++ 4 files changed, 74 insertions(+) create mode 100644 .tekton/docker-secret.yaml create mode 100644 .tekton/open-flights-pipeline.yaml create mode 100644 .tekton/pipeline-run.yaml diff --git a/.gitignore b/.gitignore index 24352803..74d29fe5 100644 --- a/.gitignore +++ b/.gitignore @@ -27,3 +27,4 @@ yarn-debug.log* # Ignore application configuration /config/application.yml +/.tekton/shared-data-pv.yaml diff --git a/.tekton/docker-secret.yaml b/.tekton/docker-secret.yaml new file mode 100644 index 00000000..b4b92bff --- /dev/null +++ b/.tekton/docker-secret.yaml @@ -0,0 +1,8 @@ +apiVersion: v1 +data: + config.json: 'base64 docker encoded credentials' +kind: Secret +metadata: + name: docker-credentials + namespace: default +# type: kubernetes.io/dockerconfigjson diff --git a/.tekton/open-flights-pipeline.yaml b/.tekton/open-flights-pipeline.yaml new file mode 100644 index 00000000..c607c340 --- /dev/null +++ b/.tekton/open-flights-pipeline.yaml @@ -0,0 +1,38 @@ +apiVersion: tekton.dev/v1beta1 +kind: Pipeline +metadata: + name: open-flights-ci +spec: + description: | + This pipeline clones a git repo, builds a Docker image with Kaniko and + pushes it to a registry + params: + - name: repo-url + type: string + - name: image-reference + type: string + workspaces: + - name: shared-data + - name: docker-credentials + tasks: + - name: fetch-source + taskRef: + name: git-clone + workspaces: + - name: output + workspace: shared-data + params: + - name: url + value: $(params.repo-url) + - name: build-push + runAfter: ["fetch-source"] + taskRef: + name: kaniko + workspaces: + - name: source + workspace: shared-data + - name: dockerconfig + workspace: docker-credentials + params: + - name: IMAGE + value: $(params.image-reference) \ No newline at end of file diff --git a/.tekton/pipeline-run.yaml b/.tekton/pipeline-run.yaml new file mode 100644 index 00000000..c686c256 --- /dev/null +++ b/.tekton/pipeline-run.yaml @@ -0,0 +1,27 @@ +apiVersion: tekton.dev/v1beta1 +kind: PipelineRun +metadata: + generateName: clone-build-push-run- +spec: + pipelineRef: + name: open-flights-ci + podTemplate: + securityContext: + fsGroup: 65532 + workspaces: + - name: shared-data + volumeClaimTemplate: + spec: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 4Gi + - name: docker-credentials + secret: + secretName: docker-credentials + params: + - name: repo-url + value: https://github.com/hawkinswinja/open-flights.git + - name: image-reference + value: hawkinswinja/open-flights:v2 \ No newline at end of file