Skip to content

Commit

Permalink
Working on dockerization automatic deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
scx1332 authored Apr 6, 2024
1 parent ec5055e commit b6063f9
Show file tree
Hide file tree
Showing 18 changed files with 339 additions and 38 deletions.
13 changes: 13 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
**/.husky
**/.idea
**/.vscode
**/node_modules
**/.env
.dockerignore
**/.gitignore
**/*.env
**/.git
**/.gitmodules
**/.github
**/Dockerfile
**/docker-compose.yml
52 changes: 52 additions & 0 deletions .github/workflows/build_and_deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#Location: .github/workflows/custom_config.yml

name: Build and push containers to Github Container Registry and apply rolling update
on:
push:
branches:
- staging
- develop
- main
tags:
- v*

jobs:
build:
runs-on: ubuntu-latest
permissions:
packages: write
contents: read
steps:
- uses: actions/checkout@v4
with:
submodules: 'recursive'

- name: Getting image tag
uses: actions/github-script@v6
id: get_image_tag
with:
result-encoding: string
script: |
return context.payload.ref.replace(/.*\//, '');
- name: Create and push docker image
run: |
# login to ghcr.io
docker login ghcr.io -u ${{ github.actor }} -p ${{ secrets.GITHUB_TOKEN }}
# build with full metadata
docker build \
--label "org.opencontainers.image.source=https://github.com/${GITHUB_REPOSITORY}" \
--label "org.opencontainers.image.description=Deposit payment example dockerized app" \
--label "org.opencontainers.image.licenses=MIT" \
-t ghcr.io/golemfactory/deposit_example:${{ steps.get_image_tag.outputs.result }} \
--build-arg BACKEND_URL=http://deposit.dev.golem.network:5174 \
.
# push one image with two tags into repository
docker push --all-tags ghcr.io/golemfactory/deposit_example
- name: Notify Staging
continue-on-error: true
if: ${{ steps.get_image_tag.outputs.result == 'staging' }}
run: curl http://deposit.dev.golem.network:5000/release/pull
40 changes: 40 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Build docker files

on:
push:

permissions:
packages: write
contents: write

jobs:

build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
with:
submodules: 'recursive'

- name: Create and push docker image
run: |
# login to ghcr.io
docker login ghcr.io -u ${{ github.actor }} -p ${{ secrets.GITHUB_TOKEN }}
# build with full metadata
docker build \
--label "org.opencontainers.image.source=https://github.com/${GITHUB_REPOSITORY}" \
--label "org.opencontainers.image.description=Deposit payment example dockerized app" \
--label "org.opencontainers.image.licenses=MIT" \
-t ghcr.io/golemfactory/deposit_example:latest \
--build-arg BACKEND_URL=http://deposit.dev.golem.network:5174 \
.
# push one image with two tags into repository
docker push --all-tags ghcr.io/golemfactory/deposit_example
- name: Notify Develop Server
continue-on-error: true
if: ${{ steps.get_image_tag.outputs.result == 'develop' }}
run: curl http://deposit.dev.golem.network.:5000/release/pull
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ node_modules
dist
backend/.env.local
temp
.env
6 changes: 3 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
[submodule "golem-js"]
path = golem-js
url = git@github.com:golemfactory/golem-js.git
url = https://github.com/golemfactory/golem-js.git
branch = pociej/deposit
[submodule "ya-ts-client"]
path = ya-ts-client
url = git@github.com:golemfactory/ya-ts-client.git
url = https://github.com/golemfactory/ya-ts-client.git
branch = pociej/deposit
[submodule "golem-sdk-task-executor"]
path = golem-sdk-task-executor
url = git@github.com:golemfactory/golem-sdk-task-executor.git
url = https://github.com/golemfactory/golem-sdk-task-executor.git
branch = pociej/deposit

28 changes: 0 additions & 28 deletions .husky/commit-msg

This file was deleted.

1 change: 0 additions & 1 deletion .husky/pre-commit

This file was deleted.

19 changes: 19 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
ARG BACKEND_URL=http://127.0.0.1:5174

FROM node:20-bullseye

RUN apt-get update && apt-get install -y vim

RUN npm install -g pnpm serve

# Set the working directory
WORKDIR /app
COPY . /app

ARG BACKEND_URL
ENV VITE_BACKEND_URL=$BACKEND_URL
RUN echo "The backend URL is $BACKEND_URL"
RUN mkdir /app/temp

RUN pnpm install
RUN pnpm build:all
3 changes: 2 additions & 1 deletion backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"main": "index.ts",
"scripts": {
"dev": "concurrently -k \"tsc -w\" \"nodemon --env-file=.env.local ./dist/index.js\"",
"build": "tsc"
"build": "tsc",
"run": "node ./dist/index.js"
},
"type": "module",
"keywords": [],
Expand Down
81 changes: 81 additions & 0 deletions deploy/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
services:
# application service
backend:
image: ghcr.io/golemfactory/deposit_example:${DEPLOY_BRANCH:-latest}
command: pnpm run run
working_dir: /app/backend
environment:
- YAGNA_APPKEY=66667777888
- YAGNA_API_URL=http://yagna:7465
- JWT_SECRET=dup]a
- JWT_TOKEN_EXPIRATION=1d
- JWT_REFRESH_TOKEN_EXPIRATION=7d
- JWT_ISSUER=golem.network
- MONGO_URI=mongodb://${MONGO_ROOT_USER}:${MONGO_ROOT_PASSWORD}@mongo:27017/
- HOST=0.0.0.0
- PORT=5174
- DB_NAME=depositDB
- DEPOSIT_CONTRACT_ADDRESS=0xb9919c8D8D384d93C195503064A3b303Ea8Fdbaa
ports:
- "5174:5174"
depends_on:
- yagna
- mongo

frontend:
image: ghcr.io/golemfactory/deposit_example:${DEPLOY_BRANCH:-latest}
command: pnpm run run
working_dir: /app/frontend
environment:
- YAGNA_APPKEY=66667777888
- YAGNA_API_URL=http://yagna:7465
- JWT_SECRET=dup]a
- JWT_TOKEN_EXPIRATION=1d
- JWT_REFRESH_TOKEN_EXPIRATION=7d
- JWT_ISSUER=golem.network
- MONGO_URI=mongodb://${MONGO_ROOT_USER}:${MONGO_ROOT_PASSWORD}@mongo:27017/
- HOST=0.0.0.0
- PORT=5174
- DB_NAME=depositDB
- DEPOSIT_CONTRACT_ADDRESS=0xb9919c8D8D384d93C195503064A3b303Ea8Fdbaa
ports:
- "3000:3000"
depends_on:
- backend
# yagna service
yagna:
build:
context: ../yagna
dockerfile: Dockerfile
args:
- YAGNA_VERSION=pre-rel-v0.15.0-deposits-beta1
command: yagna service run
environment:
- YAGNA_AUTOCONF_APPKEY=66667777888
- YAGNA_AUTOCONF_ID_SECRET=0000000000000000000000000000000000000000000000000000000222222222
- YAGNA_API_URL=http://0.0.0.0:7465
- SUBNET=change_me
- YA_NET_BIND_URL=udp://0.0.0.0:0
# mongo service
mongo:
image: mongo
environment:
- MONGO_INITDB_ROOT_USERNAME=${MONGO_ROOT_USER}
- MONGO_INITDB_ROOT_PASSWORD=${MONGO_ROOT_PASSWORD}
- MONGO_INITDB_DATABASE=project
# mongo express service
mongo-express:
image: mongo-express
environment:
- ME_CONFIG_MONGODB_SERVER=mongo
- ME_CONFIG_MONGODB_PORT=27017
- ME_CONFIG_MONGODB_ENABLE_ADMIN=false
- ME_CONFIG_MONGODB_AUTH_DATABASE=admin
- ME_CONFIG_MONGODB_AUTH_USERNAME=${MONGO_ROOT_USER}
- ME_CONFIG_MONGODB_AUTH_PASSWORD=${MONGO_ROOT_PASSWORD}
- ME_CONFIG_BASICAUTH_USERNAME=${MONGOEXPRESS_LOGIN}
- ME_CONFIG_BASICAUTH_PASSWORD=${MONGOEXPRESS_PASSWORD}
depends_on:
- mongo
ports:
- "8888:8081"
18 changes: 18 additions & 0 deletions deploy/npm_server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const express = require('express');
const { spawn } = require('child_process');

const app = express();

app.get('/release/pull', (req, res) => {
const deployProcess = spawn('/bin/bash', ['-c', './script.sh'],
{
cwd: process.cwd(),
stdio: "inherit"
}
);
res.send('Hello World');
});

const server = app.listen(5000, '0.0.0.0', () => {
console.log('Server running');
});
10 changes: 10 additions & 0 deletions deploy/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "deposit-payments-deploy-updater",
"version": "1.0.0",
"dependencies": {
"express": "^4.17.1"
},
"scripts": {
"start": "node npm_server.js"
}
}
7 changes: 7 additions & 0 deletions deploy/script.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
for i in {1..10}
do
docker-compose pull
# docker-compose config
docker-compose up -d
sleep 10
done
61 changes: 61 additions & 0 deletions docker-compose-dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
services:
# application service
app:
build:
context: .
dockerfile: Dockerfile
args:
- BACKEND_URL=${BACKEND_URL:-http://127.0.0.1:5174}
command: tail -F anything
environment:
- YAGNA_APPKEY=66667777888
- YAGNA_API_URL=http://yagna:7465
- JWT_SECRET=dup]a
- JWT_TOKEN_EXPIRATION=1d
- JWT_REFRESH_TOKEN_EXPIRATION=7d
- JWT_ISSUER=golem.network
- MONGO_URI=mongodb://${MONGO_ROOT_USER}:${MONGO_ROOT_PASSWORD}@mongo:27017/
- HOST=0.0.0.0
- PORT=5174
- DB_NAME=depositDB
- DEPOSIT_CONTRACT_ADDRESS=0xb9919c8D8D384d93C195503064A3b303Ea8Fdbaa
ports:
- "3000:3000"
- "5174:5174"
# yagna service
yagna:
build:
context: ./yagna
dockerfile: Dockerfile
args:
- YAGNA_VERSION=pre-rel-v0.15.0-deposits-beta1
command: yagna service run
environment:
- YAGNA_AUTOCONF_APPKEY=66667777888
- YAGNA_AUTOCONF_ID_SECRET=0000000000000000000000000000000000000000000000000000000222222222
- YAGNA_API_URL=http://0.0.0.0:7465
- SUBNET=change_me
- YA_NET_BIND_URL=udp://0.0.0.0:0
# mongo service
mongo:
image: mongo
environment:
- MONGO_INITDB_ROOT_USERNAME=${MONGO_ROOT_USER}
- MONGO_INITDB_ROOT_PASSWORD=${MONGO_ROOT_PASSWORD}
- MONGO_INITDB_DATABASE=project
# mongo express service
mongo-express:
image: mongo-express
environment:
- ME_CONFIG_MONGODB_SERVER=mongo
- ME_CONFIG_MONGODB_PORT=27017
- ME_CONFIG_MONGODB_ENABLE_ADMIN=false
- ME_CONFIG_MONGODB_AUTH_DATABASE=admin
- ME_CONFIG_MONGODB_AUTH_USERNAME=${MONGO_ROOT_USER}
- ME_CONFIG_MONGODB_AUTH_PASSWORD=${MONGO_ROOT_PASSWORD}
- ME_CONFIG_BASICAUTH_USERNAME=${MONGOEXPRESS_LOGIN}
- ME_CONFIG_BASICAUTH_PASSWORD=${MONGOEXPRESS_PASSWORD}
depends_on:
- mongo
ports:
- "8888:8081"
1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"scripts": {
"dev": "vite",
"build": "tsc && vite build",
"run": "serve dist -l tcp://0.0.0.0:3000",
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"preview": "vite preview"
},
Expand Down
Loading

0 comments on commit b6063f9

Please sign in to comment.