Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hardhat Dockerization #61

Merged
merged 27 commits into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,12 @@ cache/
artifacts/
.openzeppelin/
.husky/
contracts/mocks/
contracts/upgrades/

scripts/log.txt
scripts/log.log
scripts/test.js

scripts/helpers/local-setup.devnet.sh
.DS_Store
64 changes: 64 additions & 0 deletions .github/workflows/docker-build-and-push.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Build and push docker image when tagged with v[0-9]* or when pushed to dev branch

name: Build & Push Docker on Push

on:
push:
tags:
- v[0-9]*
branches:
- dev

env:
KEY: '0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80'
KEY2: '0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d'
KEY3: '0x5de4111afa1a4b94908f83103eb1f1706367c2e68ca870fc3fb9a804cdab365a'

jobs:
test:
runs-on: ubuntu-latest
name: Hardhat unit tests
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install Node.js
uses: actions/setup-node@v4
- name: Install the dependencies
run: npm install
- name: Run the tests
run: npm run coverage
build:
name: Build and push Docker image
runs-on: ubuntu-latest
needs: [test]
steps:
- name: Check out code
uses: actions/checkout@v4
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.TF_AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.TF_AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-1
- name: Login to Amazon ECR Public
id: login-ecr-public
uses: aws-actions/amazon-ecr-login@v2
with:
registry-type: public
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2
- name: Set outputs
id: vars
run: echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
- name: Build and push Docker image
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_PUBLIC_REGISTRY: ${{ steps.login-ecr-public.outputs.registry }}
REGISTRY_ALIAS: dlc-link
ECR_REPOSITORY: dlc-solidity
IMAGE_TAG: ${{ github.ref_name }}
run: |
docker build -t $ECR_PUBLIC_REGISTRY/$REGISTRY_ALIAS/$ECR_REPOSITORY:$IMAGE_TAG -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
docker push $ECR_PUBLIC_REGISTRY/$REGISTRY_ALIAS/$ECR_REPOSITORY:$IMAGE_TAG
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
59 changes: 59 additions & 0 deletions .github/workflows/hardhat-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: Hardhat Tests & ECR Private

on:
pull_request:
branches:
- dev
- master
types:
- opened
- reopened
- synchronize

env:
KEY: '0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80'
KEY2: '0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d'
KEY3: '0x5de4111afa1a4b94908f83103eb1f1706367c2e68ca870fc3fb9a804cdab365a'

jobs:
test:
runs-on: ubuntu-latest
name: Hardhat unit tests
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install Node.js
uses: actions/setup-node@v4
- name: Install the dependencies
run: npm install
- name: Run the tests
run: npm run coverage

# This will push a temp image to ECR private
build:
name: Build and push Docker image
runs-on: ubuntu-latest
needs: [test]
steps:
- name: Check out code
uses: actions/checkout@v4
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.TF_AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.TF_AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-1
- name: Login to Amazon ECR Public
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2
- name: Set outputs
id: vars
run: echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
- name: Build and push Docker image
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: dlc-solidity
IMAGE_TAG: test-${{ steps.vars.outputs.sha_short }}
run: |
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@
.openzeppelin

log.txt
log.log
test.js

docker/deploymentFiles
deploymentFiles/localhost

local-setup.devnet.sh

### Node ###
Expand Down
18 changes: 13 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,28 @@ COPY ./contracts /app/dlc-solidity/contracts
COPY ./scripts /app/dlc-solidity/scripts
COPY ./test /app/dlc-solidity/test
COPY ./package.json /app/dlc-solidity/package.json
# COPY ./package-lock.json /app/dlc-solidity/package-lock.json
COPY ./package-lock.json /app/dlc-solidity/package-lock.json
COPY ./docker/hardhat.config.docker.js /app/dlc-solidity/hardhat.config.js

WORKDIR /app/dlc-solidity

RUN npm install
RUN npm ci

# copy entrypoint
# todo
RUN npx hardhat compile

FROM node:20-alpine

COPY --from=dlc-solidity-build /app/dlc-solidity /app/dlc-solidity

WORKDIR /app/dlc-solidity

ENTRYPOINT [ "npx", "hardhat", "node" ]
COPY ./docker/scripts/check-service.sh /check-service.sh
RUN chmod +x /check-service.sh

# Copy the entrypoint script into the Docker image
COPY ./docker/entrypoint.sh /app/dlc-solidity/entrypoint.sh
RUN chmod +x /app/dlc-solidity/entrypoint.sh

COPY ./docker/scripts/deploy-all.js /app/dlc-solidity/docker/scripts/deploy-all.js

ENTRYPOINT [ "/app/dlc-solidity/entrypoint.sh" ]
43 changes: 0 additions & 43 deletions contracts/upgrades/DLCLinkLibraryV2Test.sol

This file was deleted.

Loading