Skip to content

Commit

Permalink
Dockerfile able to start from script file
Browse files Browse the repository at this point in the history
  • Loading branch information
Mubangizi committed May 9, 2024
1 parent 55948a0 commit 9b0c1c7
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 7 deletions.
113 changes: 113 additions & 0 deletions .github/workflows/staging.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
---
name: stating

on:
push:
branches:
- develop

workflow_dispatch:

jobs:
build:
outputs:
image: ${{ steps.export.outputs.image }}
tag: ${{ steps.export.outputs.tag }}

runs-on: ubuntu-latest
env:
image: cranecloud/monitoring-api

steps:
- name: Checkout
uses: actions/checkout@v2

- name: Install (Buildx)
uses: docker/setup-buildx-action@v1

- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- id: meta
name: Tag
uses: docker/metadata-action@v3
with:
flavor: |
latest=true
images: ${{ env.image }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=sha
- name: Build
uses: docker/build-push-action@v2
with:
cache-from: type=gha
cache-to: type=gha,mode=max
context: .
labels: ${{ steps.meta.outputs.labels }}
push: true
tags: ${{ steps.meta.outputs.tags }}

- id: export
name: Export
uses: actions/github-script@v5
with:
script: |
const metadata = JSON.parse(`${{ steps.meta.outputs.json }}`)
const fullUrl = metadata.tags.find((t) => t.includes(':sha-'))
if (fullUrl == null) {
core.error('Unable to find sha tag of image')
} else {
const tag = fullUrl.split(':')[1]
core.setOutput('image', fullUrl)
core.setOutput('tag', tag)
}
Microservice:
name: Deploy (Microservice)

needs:
- Build

runs-on: ubuntu-latest
env:
namespace: cranecloud-microservice
image: cranecloud/monitoring-api

steps:
- name: Checkout code
uses: actions/checkout@v2

- uses: azure/k8s-set-context@v1
with:
kubeconfig: ${{ secrets.RENU_KUBECONFIG}}

- name: Helm Release
run: |
helm upgrade --install --create-namespace \
monitoring-api ./helm/chart \
--values helm/values.micro.yaml \
--namespace $namespace \
--set image.tag="${{ needs.build.outputs.tag }}" \
--set environment.ADMIN_MYSQL_PASSWORD="${{ secrets.STAGING_ADMIN_MYSQL_PASSWORD }}" \
--set environment.ADMIN_PSQL_PASSWORD="${{ secrets.STAGING_ADMIN_PSQL_PASSWORD }}" \
--set environment.APP_MAIL_PASSWORD="${{ secrets.STAGING_APP_MAIL_PASSWORD }}" \
--set environment.DATABASE_URI="${{ secrets.MICROSERVICE_DATABASE_URI }}" \
--set environment.MONGO_URI="${{ secrets.STAGING_MONGO_URI }}" \
--set environment.FLASK_APP_SALT="${{ secrets.STAGING_FLASK_APP_SALT }}" \
--set environment.FLASK_APP_SECRET="${{ secrets.STAGING_FLASK_APP_SECRET }}" \
--set environment.GITHUB_CLIENT_SECRET="${{ secrets.STAGING_GITHUB_CLIENT_SECRET }}" \
--set environment.NEW_RELIC_LICENSE_KEY="${{ secrets.STAGING_NEW_RELIC_LICENSE_KEY }}" \
--set environment.KUBE_SERVICE_PORT="${{ secrets.STAGING_KUBE_SERVICE_PORT }}" \
--set environment.LOGGER_APP_URL="${{ secrets.MICROSERVICE_LOGGER_APP_URL }}" \
--timeout=300s
- name: Monitor Rollout
run: |
kubectl rollout status deployment/cranecloud-backend --timeout=300s --namespace $namespace
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ COPY . /app


# make port available to the world outside this container
EXPOSE 4000
EXPOSE 5000

# connect to start script when db is being used
CMD ["flask", "run", "--host=0.0.0.0", "--port=4000"]
ENTRYPOINT ["sh", "/app/scripts/start.sh"]
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ services:
database:
restart: always
image: postgres:10.8-alpine
container_name: postgres-db
container_name: monitoring-postgres-db
environment:
POSTGRES_USER: postgres
POSTGRES_DB: cc-monitoring
Expand All @@ -17,7 +17,7 @@ services:
build:
context: .
dockerfile: Dockerfile
container_name: flask-api
container_name: monitoring-api
environment:
FLASK_APP_SECRET:
JWT_SALT:
Expand Down
6 changes: 3 additions & 3 deletions scripts/start.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#! /bin/bash
#!/bin/bash

# source .env

# apply migrations onto db
# flask db upgrade
flask db upgrade

# start server
flask run --host=0.0.0.0 --port=50000
flask run --host=0.0.0.0 --port=5000

0 comments on commit 9b0c1c7

Please sign in to comment.