Skip to content

Commit

Permalink
Add support for docker builds (#371)
Browse files Browse the repository at this point in the history
* Add support for docker builds

* update UI nginx config

* Add ci job

* Update gh actions files

* update actions versions

* add docker-compose

* fix project name

* fix workdir

* test building docker

* Move workflow to github actions (#375)

* test gh actions file

* test new gh workflow

* test running services

* add actions cache

* cleanup jobs

* add test jobs

* update ci job

* expose docker port

* test different node image

* set env to qa

* add contracts deploy

* update workflow

* Cleanup job names

* add bb testing

* Update bb version

* clear branches filter

* Rm bb run due to job being stuck on db conn

* test without configs

* Disable bb server tests

* revert local-deps override

* Remove local-deps

* debug ci job

* update pgsql service

* Release complete pipeline

* cleanup

* revert changes

* Update docker images workflow

* add export to docker

* Update workflow

* test docker builds

* forcefully assign builder

* temp remove arm64 image

* compile contracts before dockerbuild

* update images

* Update dockerfiles

* Updates
  • Loading branch information
sm47916 authored Dec 13, 2023
1 parent 384c024 commit b69ecf3
Show file tree
Hide file tree
Showing 11 changed files with 501 additions and 38 deletions.
17 changes: 13 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
version: 2.1

jobs:
test:
working_directory: ~/ethlance
Expand All @@ -10,7 +9,13 @@ jobs:
ETHLANCE_ENV: qa
# Secondary container images on common network.
- image: trufflesuite/ganache:v7.9.1
command: [-v -m "easy leave proof verb wait patient fringe laptop intact opera slab shine", -p 8550, -b 0.5, --chain.allowUnlimitedContractSize=true]
command:
[
-v -m "easy leave proof verb wait patient fringe laptop intact opera slab shine",
-p 8550,
-b 0.5,
--chain.allowUnlimitedContractSize=true,
]
- image: district0x/ipfs-daemon:latest
- image: postgres:latest
environment:
Expand All @@ -19,25 +24,30 @@ jobs:
POSTGRES_DB: ethlance-test
steps:
- checkout

- restore_cache:
name: Restore ethlance top-level npm package cache
keys:
- npm-dependencies-ethlance-{{ checksum "yarn.lock" }}
- run:
name: Install ethlance top-level node modules
command: yarn install

- restore_cache:
name: Restore ethlance server npm package cache
keys:
- npm-dependencies-ethlance-{{ checksum "server/yarn.lock" }}

- run:
name: Install ethlance server node modules
command: cd server && yarn install

- save_cache:
name: Save ethlance server npm package cache
key: npm-dependencies-ethlance-{{ checksum "server/yarn.lock" }}
paths:
- ./server/node_modules

- save_cache:
name: Save ethlance top-level npm package cache
key: npm-dependencies-ethlance-{{ checksum "yarn.lock" }}
Expand All @@ -51,8 +61,7 @@ jobs:
command: bb run-server-tests

workflows:
version: 2
build_and_deploy:
build:
jobs:
- test:
context: district0x
122 changes: 122 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
Dockerfile
.git
Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# Snowpack dependency directory (https://snowpack.dev/)
web_modules/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env
.env.test

# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache

# Next.js build output
.next
out

# Nuxt.js build / generate output
.nuxt
dist

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port

# Stores VSCode versions used for testing VSCode extensions
.vscode-test

# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.


# clj-kondo cache
.clj-kondo/.cache/
182 changes: 148 additions & 34 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,110 @@ name: Docker Image CI

on:
push:
branches: [ "add_dockerfiles", "newlance" ]
branches: [ "master", "main", "newlance"]
pull_request:
branches: [ "add_dockerfiles", "newlance" ]


permissions:
contents: read

jobs:
run_tests:
runs-on: ubuntu-latest
name: Run tests
env:
ETHLANCE_ENV: qa
services:
ipfs-daemon:
image: district0x/ipfs-daemon:latest
postgres:
image: postgres:latest
ports:
- 5432:5432
env:
POSTGRES_PASSWORD: pass
POSTGRES_USER: ethlanceuser
POSTGRES_DB: ethlance-test
# Set health checks to wait until postgres has started
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- name: Checkout ethlance code
uses: actions/checkout@v4

- name: Checkout ethlance-configs repo
uses: actions/checkout@v4
with:
repository: district0x/ethlance-config
path: ethlance-config
token: ${{ secrets.ETHLANCE_CONFIG_PAT }}
ref: docker_build

- name: Run ganache service
run: |
docker run --rm -d --name ganache -p 8550:8550 trufflesuite/ganache:v7.9.1 -v -m "easy leave proof verb wait patient fringe laptop intact opera slab shine" -p 8550 -b 0.5 --chain.allowUnlimitedContractSize=true
- name: Restore Top level cache directory for Ethlance
uses: actions/cache@v3
id: yarn-cache-top-level
with:
path: ./node_modules
key: ${{ runner.os }}-ethlance-top-level-yarn-${{ hashFiles('yarn.lock') }}
restore-keys: |
${{ runner.os }}-ethlance-top-level-yarn-
- name: Install ethlance top-level node modules
run: |
yarn install
- name: Restore Server cache directory for Ethlance
uses: actions/cache@v3
id: yarn-cache-server
with:
path: ./server/node_modules
key: ${{ runner.os }}-ethlance-server-yarn-${{ hashFiles('server/yarn.lock') }}
restore-keys: |
${{ runner.os }}-ethlance-server-yarn-
- name: Install ethlance server node modules
run: |
cd server
yarn install
cd ..
- name: Deploy contracts to ganache-test
run: |
npx truffle migrate --network ganache-test --reset
- name: Setup Babashka
uses: turtlequeue/[email protected]
with:
babashka-version: 1.3.186

- name: Check bb version
run: bb --version

- name: Run server tests
run: bb run-server-tests

- name: Stop Ganache service
run: docker rm -f ganache

docker_build:
name: Build images and deploy contracts
needs: run_tests
strategy:
matrix:
image: ["server", "ui"]
env: ["qa"]
permissions:
contents: read # for actions/checkout to fetch code
name: Docker Build
contents: read
runs-on: ubuntu-latest
steps:
- name: Checkout ethlance code
uses: actions/checkout@v4

- name: Checkout ethlance-configs repo
uses: actions/checkout@v4
with:
Expand All @@ -35,30 +118,61 @@ jobs:
run: |
cp -r ethlance-config/config .
ls -lah config/
# - name: Set up QEMU
# uses: docker/setup-qemu-action@v2

# - name: Set up Docker Buildx
# uses: docker/setup-buildx-action@v2

# - name: Configure AWS Credentials
# uses: aws-actions/configure-aws-credentials@v1
# with:
# aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
# aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
# aws-region: ${{ secrets.AWS_DEFAULT_REGION }}

# - name: Login to Amazon ECR
# id: login-ecr
# uses: aws-actions/amazon-ecr-login@v1

# - name: Build and push
# uses: docker/build-push-action@v4
# with:
# context: .
# platforms: linux/amd64,linux/arm64
# file: docker-builds/${{ matrix.image }}/Dockerfile
# build-args: BUILD_ENV=${{ matrix.env }}
# push: true
# tags: ${{ secrets.ECR_REGISTRY }}/streamtide-${{ matrix.image }}:latest-${{ matrix.env }}
- name: Restore Top level cache directory for Ethlance
uses: actions/cache@v3
id: yarn-cache-top-level
with:
path: ./node_modules
key: ${{ runner.os }}-ethlance-top-level-yarn-${{ hashFiles('yarn.lock') }}
restore-keys: |
${{ runner.os }}-ethlance-top-level-yarn-
- name: Install ethlance top-level node modules
run: |
yarn install
- name: Deploy contracts for ${{ matrix.env }}
run: |
ETHLANCE_ENV=${{ matrix.env }} npx truffle migrate --network ethlance.mad.is-testnet --reset
- name: Set up QEMU
id: setup-qemu
uses: docker/setup-qemu-action@v2

- name: Set up Docker Buildx
id: setup-buildx
uses: docker/setup-buildx-action@v2

- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_DEFAULT_REGION }}

- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2

- name: Build and push UI
uses: docker/build-push-action@v4
with:
context: .
platforms: linux/amd64
builder: ${{ steps.setup-buildx.outputs.name }}
file: docker-builds/ui/Dockerfile
build-args: BUILD_ENV=${{ matrix.env }}
push: true
tags: ${{ secrets.ECR_REGISTRY }}/ethlance-ui:latest-${{ matrix.env }}

- name: Build and push Server
uses: docker/build-push-action@v4
with:
context: .
builder: ${{ steps.setup-buildx.outputs.name }}
platforms: linux/amd64
file: docker-builds/server/Dockerfile
build-args: BUILD_ENV=${{ matrix.env }}
push: true
tags: ${{ secrets.ECR_REGISTRY }}/ethlance-server:latest-${{ matrix.env }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ designs/deploy
tags
temp
release
config
Loading

0 comments on commit b69ecf3

Please sign in to comment.