Skip to content

Commit

Permalink
Add docker + deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
OriHoch committed Jan 19, 2024
1 parent 69030fb commit 2759edd
Show file tree
Hide file tree
Showing 645 changed files with 85 additions and 95,243 deletions.
39 changes: 39 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: CI
on:
push:
jobs:
ci:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v2
- env:
DOCKER_APP_IMAGE_NAME: "ghcr.io/hasadna/open-bus-backend/open-bus-backend"
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
HASADNA_K8S_DEPLOY_KEY: ${{ secrets.HASADNA_K8S_DEPLOY_KEY }}
run: |
echo "${GITHUB_TOKEN}" | docker login ghcr.io -u hasadna --password-stdin &&\
if docker pull "${DOCKER_APP_IMAGE_NAME}:latest"; then
CACHE_FROM_ARG="--cache-from ${DOCKER_APP_IMAGE_NAME}:latest"
else
CACHE_FROM_ARG=""
fi &&\
docker build $CACHE_FROM_ARG --build-arg VERSION=${GITHUB_SHA} -t app . &&\
docker tag app "${DOCKER_APP_IMAGE_NAME}:${GITHUB_SHA}" &&\
docker push "${DOCKER_APP_IMAGE_NAME}:${GITHUB_SHA}" &&\
if [ "${GITHUB_REF}" == "refs/heads/main" ]; then
docker tag app "${DOCKER_APP_IMAGE_NAME}:latest" &&\
docker push "${DOCKER_APP_IMAGE_NAME}:latest" &&\
if ! git log -1 --pretty=format:"%s" | grep -- --no-deploy; then
cd `mktemp -d` &&\
echo "${HASADNA_K8S_DEPLOY_KEY}" > hasadna_k8s_deploy_key &&\
chmod 400 hasadna_k8s_deploy_key &&\
export GIT_SSH_COMMAND="ssh -i `pwd`/hasadna_k8s_deploy_key -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no" &&\
git clone git@github.com:hasadna/hasadna-k8s.git &&\
cd hasadna-k8s &&\
python update_yaml.py '{"backendImage":"'"${DOCKER_APP_IMAGE_NAME}:${GITHUB_SHA}"'"}' apps/openbus/values-hasadna-auto-updated.yaml &&\
git config --global user.name "Open Bus Backend CI" &&\
git config --global user.email "open-bus-backend-ci@localhost" &&\
git add apps/openbus/values-hasadna-auto-updated.yaml && git commit -m "automatic update of open bus backend" &&\
git push origin master
fi
fi
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules/
.env
6 changes: 6 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM node:18@sha256:995a5f4314885452a4a785abc25a0fec40e26c346559e11e709d58bb7a927cf4
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm install
COPY . .
CMD ["node", "index.js"]
2 changes: 1 addition & 1 deletion node_modules/call-bind/LICENSE → LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2020 Jordan Harband
Copyright (c) 2024 The Public Knowledge Workshop

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Open Bus Backend

## Configuration

The following environment variables are required:

* GITHUB_TOKEN
* GITHUB_OWNER
* GITHUB_REPO

## Local Development

```
npm install
node index.js
curl -X POST http://localhost:3001/create-issue -H "Content-Type: application/json" -d '{
"title": "Sample Title",
"contactName": "John Doe",
"contactEmail": "john.doe@example.com",
"description": "Detailed description of the issue.",
"environment": "Operating system, software version, hardware specifics.",
"expectedBehavior": "What you expect to happen.",
"actualBehavior": "What actually happens.",
"reproducibility": "Steps to reproduce the issue."
}'
```

## Running with Docker

```
docker build -t backend .
docker run -it -p 3001:3001 -e GITHUB_TOKEN -e GITHUB_OWNER -e GITHUB_REPO backend
```
6 changes: 3 additions & 3 deletions controllers/issueController.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ const createIssue = async (req, res) => {

// GitHub API configuration
const token =
'TOKEN'; // Replace with the actual GitHub token
const repoOwner = 'OWNER'; // Replace with the actual owner of the repository
const repoName = 'REPO-NAME'; // Replace with the actual repository name
process.env.GITHUB_TOKEN; // Replace with the actual GitHub token
const repoOwner = process.env.GITHUB_OWNER; // Replace with the actual owner of the repository
const repoName = process.env.GITHUB_REPO; // Replace with the actual repository name

// Create the GitHub issue
const response = await axios.post(
Expand Down
12 changes: 0 additions & 12 deletions node_modules/.bin/mime

This file was deleted.

17 changes: 0 additions & 17 deletions node_modules/.bin/mime.cmd

This file was deleted.

28 changes: 0 additions & 28 deletions node_modules/.bin/mime.ps1

This file was deleted.

Loading

0 comments on commit 2759edd

Please sign in to comment.