Skip to content

Commit

Permalink
fix cd pipeline for code proposals
Browse files Browse the repository at this point in the history
  • Loading branch information
tenmoves committed Mar 29, 2023
1 parent d750034 commit b0a0d5d
Show file tree
Hide file tree
Showing 31 changed files with 408 additions and 273 deletions.
117 changes: 58 additions & 59 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,72 +2,71 @@ name: Elixir CI

on:
push:
branches: [ master, develop, testnet ]
branches: [master, develop, testnet]
pull_request:
branches: [ master, develop, testnet ]
branches: [master, develop, testnet]

env:
MIX_ENV: test

jobs:
build:

name: Build and test
runs-on: ubuntu-20.04

steps:
- name: Install OS Packages
uses: mstksg/get-package@2a4b48d55d72d43ca89ae58ec9ca1397d34a1c35
with:
apt-get: libgmp-dev libssl-dev libtinfo-dev libsystemd-dev zlib1g-dev libsodium-dev autoconf-archive libcmocka0 libcmocka-dev procps iproute2 build-essential git pkg-config gcc libtool automake libssl-dev uthash-dev autoconf doxygen libjson-c-dev libini-config-dev libcurl4-openssl-dev libltdl-dev libtss2-dev tss2
- uses: actions/checkout@v2
- name: Set up Elixir
uses: erlef/setup-beam@988e02bfe678367a02564f65ca2e37726dc0268f
id: beam
with:
elixir-version: '1.14.1' # Define the elixir version [required]
otp-version: '25.1' # Define the OTP version [required]
- name: Restore dependencies cache
uses: actions/cache@v3
id: mix-cache
with:
path: deps
key: ${{ runner.os }}-elixir-${{ steps.beam.outputs.elixir-version }}-${{ steps.beam.outputs.otp-version }}-mix-${{ hashFiles('**/mix.lock') }}
restore-keys: ${{ runner.os }}-elixir-${{ steps.beam.outputs.elixir-version }}-${{ steps.beam.outputs.otp-version }}-mix-
- name: Make Clean
run: mix clean
- name: Install dependencies
if: steps.mix-cache.outputs.cache-hit != 'true'
run: mix deps.get
- name: Check dependency updates
run: mix hex.outdated --within-requirements 1>/dev/null || echo 'Updates available!'
- name: Set Formatting
run: mix format --check-formatted
- name: Restore build cache
uses: actions/cache@v3
with:
path: _build
key: ${{ runner.os }}-build-elixir-${{ steps.beam.outputs.elixir-version }}-${{ steps.beam.outputs.otp-version }}-${{ hashFiles('**/mix.lock') }}
restore-keys: ${{ runner.os }}-elixir-${{ steps.beam.outputs.elixir-version }}-${{ steps.beam.outputs.otp-version }}-build-
- name: Compile the codebase
run: mix compile --warnings-as-errors
- name: Set credo
run: mix credo
- name: Run Sobelow
run: mix sobelow
- name: Run tests
run: mix test --trace
- name: Retrieve PLT Cache
uses: actions/cache@v3
id: plt-cache
with:
path: priv/plts
key: ${{ runner.os }}-plts-elixir-${{ steps.beam.outputs.elixir-version }}-${{ steps.beam.outputs.otp-version }}-${{ hashFiles('**/mix.lock') }}
restore-keys: ${{ runner.os }}-plts-elixir-${{ steps.beam.outputs.elixir-version }}-${{ steps.beam.outputs.otp-version }}-
- name: Create PLTs
if: steps.plt-cache.outputs.cache-hit != 'true'
run: |
mkdir -p priv/plts
mix dialyzer --plt
- name: Run dialyzer
run: mix dialyzer --no-check --ignore-exit-status
- name: Install OS Packages
uses: mstksg/get-package@2a4b48d55d72d43ca89ae58ec9ca1397d34a1c35
with:
apt-get: libgmp-dev libssl-dev libtinfo-dev libsystemd-dev zlib1g-dev libsodium-dev autoconf-archive libcmocka0 libcmocka-dev procps iproute2 build-essential git pkg-config gcc libtool automake libssl-dev uthash-dev autoconf doxygen libjson-c-dev libini-config-dev libcurl4-openssl-dev libltdl-dev libtss2-dev tss2
- uses: actions/checkout@v2
- name: Set up Elixir
uses: erlef/setup-beam@988e02bfe678367a02564f65ca2e37726dc0268f
id: beam
with:
elixir-version: "1.14.1" # Define the elixir version [required]
otp-version: "25.1" # Define the OTP version [required]
- name: Restore dependencies cache
uses: actions/cache@v3
id: mix-cache
with:
path: deps
key: ${{ runner.os }}-elixir-${{ steps.beam.outputs.elixir-version }}-${{ steps.beam.outputs.otp-version }}-mix-${{ hashFiles('**/mix.lock') }}
restore-keys: ${{ runner.os }}-elixir-${{ steps.beam.outputs.elixir-version }}-${{ steps.beam.outputs.otp-version }}-mix-
- name: Make Clean
run: mix clean
- name: Install dependencies
if: steps.mix-cache.outputs.cache-hit != 'true'
run: mix deps.get
- name: Check dependency updates
run: mix hex.outdated --within-requirements 1>/dev/null || echo 'Updates available!'
- name: Set Formatting
run: mix format --check-formatted
- name: Restore build cache
uses: actions/cache@v3
with:
path: _build
key: ${{ runner.os }}-build-elixir-${{ steps.beam.outputs.elixir-version }}-${{ steps.beam.outputs.otp-version }}-${{ hashFiles('**/mix.lock') }}
restore-keys: ${{ runner.os }}-elixir-${{ steps.beam.outputs.elixir-version }}-${{ steps.beam.outputs.otp-version }}-build-
- name: Compile the codebase
run: mix compile --warnings-as-errors
- name: Set credo
run: mix credo
- name: Run Sobelow
run: mix sobelow
- name: Run tests
run: mix test --trace
- name: Retrieve PLT Cache
uses: actions/cache@v3
id: plt-cache
with:
path: priv/plts
key: ${{ runner.os }}-plts-elixir-${{ steps.beam.outputs.elixir-version }}-${{ steps.beam.outputs.otp-version }}-${{ hashFiles('**/mix.lock') }}
restore-keys: ${{ runner.os }}-plts-elixir-${{ steps.beam.outputs.elixir-version }}-${{ steps.beam.outputs.otp-version }}-
- name: Create PLTs
if: steps.plt-cache.outputs.cache-hit != 'true'
run: |
mkdir -p priv/plts
mix dialyzer --plt
- name: Run dialyzer
run: mix dialyzer --no-check --ignore-exit-status
26 changes: 26 additions & 0 deletions .iex.exs
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,29 @@ alias Archethic.TransactionChain
alias Archethic.TransactionChain.Transaction
alias Archethic.TransactionChain.TransactionData
alias Archethic.BeaconChain


alias Archethic.Governance.Code.CICD.Docker
alias Archethic.Governance.Code
alias Archethic.Governance
prop = %Archethic.Governance.Code.Proposal{
address: <<0, 0, 135, 189, 175, 8, 43, 160, 49, 21, 23, 241, 61, 189, 221,
177, 45, 120, 59, 243, 80, 75, 193, 250, 119, 188, 219, 73, 209, 197, 118,
170, 122, 142>>,
previous_public_key: <<0, 1, 62, 205, 23, 142, 29, 217, 94, 202, 136, 109,
165, 135, 153, 205, 202, 132, 122, 116, 97, 18, 90, 34, 141, 225, 172, 138,
16, 138, 85, 15, 41, 149>>,
timestamp: nil,
description: "\Testing code proposal\"",
changes: "diff --git a/mix.exs b/mix.exs\nindex a82c0b3c..b94d4323 100644\n--- a/mix.exs\n+++ b/mix.exs\n@@ -4,7 +4,7 @@ defmodule Archethic.MixProject do\n def project do\n [\n app: :archethic,\n- version: \"1.0.7\",\n+ version: \"1.0.8\",\n build_path: \"_build\",\n config_path: \"config/config.exs\",\n deps_path: \"deps\",\ndiff --git a/rel/appups/archethic/1.0.7_to_1.0.8.appup b/rel/appups/archethic/1.0.7_to_1.0.8.appup\nnew file mode 100644\nindex 00000000..18b6d541\n--- /dev/null\n+++ b/rel/appups/archethic/1.0.7_to_1.0.8.appup\n@@ -0,0 +1,4 @@\n+{\"1.0.8\",\n+ [{\"1.0.7\",\n+ [{load_module,'Elixir.Archethic', []}]}],\n+ [{\"1.0.7\",\n+ [{load_module,'Elixir.Archethic', []}]}]\n+}.\n",
version: "1.0.8",
files: ["mix.exs", "rel/appups/archethic/1.0.7_to_1.0.8.appup"],
approvals: [
<<0, 0, 135, 189, 175, 8, 43, 160, 49, 21, 23, 241, 61, 189, 221, 177, 45,
120, 59, 243, 80, 75, 193, 250, 119, 188, 219, 73, 209, 197, 118, 170,
122, 142>>,
<<0, 0, 168, 220, 209, 92, 167, 255, 187, 168, 176, 63, 128, 210, 199, 35,
63, 0, 252, 36, 147, 196, 130, 249, 233, 17, 132, 0, 6, 88, 232, 198, 98,
44>>
]
}
21 changes: 6 additions & 15 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,20 @@ ARG MIX_ENV=prod

RUN apk add --no-cache --update \
build-base \
grep \
bash \
gcc \
make \
g++ \
libexecinfo-dev \
libexecinfo \
git \
npm \
python3 \
wget \
openssl \
libsodium-dev \
libexecinfo-dev \
gmp-dev


# Install hex and rebar
RUN mix local.rebar --force \
&& mix local.hex --if-missing --force
Expand All @@ -60,23 +59,15 @@ RUN git config user.name aebot \
&& git config user.email aebot@archethic.net \
&& git remote add origin https://github.com/archethic-foundation/archethic-node

# Install Dart Sass
RUN npm install -g sass

# build Sass -> CSS
RUN cd assets && \
sass --no-source-map --style=compressed css/app.scss ../priv/static/css/app.css && cd -

# build release
RUN mix do assets.deploy, distillery.release

RUN mix assets.deploy
RUN MIX_ENV=prod mix distillery.release
# gen PLT
RUN if [ $with_tests -eq 1 ]; then mix git_hooks.run pre_push ;fi

# Install
RUN mkdir -p /opt/app \
&& cd /opt/app \
&& tar zxf /opt/code/_build/${MIX_ENV}/rel/archethic_node/releases/*/archethic_node.tar.gz
&& tar zxf /opt/code/_build/${MIX_ENV}/rel/archethic_node/releases/*/archethic_node.tar.gz -C /opt/app
CMD /opt/app/bin/archethic_node foreground

################################################################################
Expand All @@ -85,7 +76,7 @@ FROM archethic-ci as build

FROM elixir:1.14.1-alpine

RUN apk add --no-cache --update bash git openssl libsodium
RUN apk add --no-cache --update bash git openssl libsodium libexecinfo

COPY --from=build /opt/app /opt/app
COPY --from=build /opt/code/.git /opt/code/.git
Expand Down
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ ifeq ($(TPM_INSTALLED),0)
$(CC) src/c/crypto/tpm/keygen.c src/c/crypto/tpm/lib.c -o priv/c_dist/tpm_keygen -I src/c/crypto/tpm/lib.h $(TPMFLAGS)
endif


clean:
rm -f priv/c_dist/*
mix archethic.clean_db
Expand Down
8 changes: 5 additions & 3 deletions assets/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ config :git_hooks,
{:cmd, "mix clean"},
{:cmd, "mix format --check-formatted"},
{:cmd, "mix compile --warnings-as-errors"},
{:cmd, "mix test --trace"},
{:cmd, "mix credo"},
{:cmd, "mix sobelow"},
{:cmd, "mix knigge.verify"},
{:cmd, "mix test --trace"},
{:cmd, "mix dialyzer"},
{:cmd, "mix check.updates"}
{:cmd, "mix dialyzer"}
# {:cmd, "mix check.updates"}
]
]
]
Expand Down
6 changes: 3 additions & 3 deletions config/dev.exs
Original file line number Diff line number Diff line change
Expand Up @@ -167,13 +167,13 @@ config :archethic, ArchethicWeb.Endpoint,
config :archethic, :throttle,
by_ip_high: [
period: 1000,
limit: 5_000
limit: System.get_env("ARCHETHIC_THROTTLE_IP_HIGH", "5000")
],
by_ip_low: [
period: 1000,
limit: 5_000
limit: System.get_env("ARCHETHIC_THROTTLE_IP_LOW", "5000")
],
by_ip_and_path: [
period: 1000,
limit: 5_000
limit: System.get_env("ARCHETHIC_THROTTLE_IP_AND_PATH", "5000")
]
6 changes: 3 additions & 3 deletions config/prod.exs
Original file line number Diff line number Diff line change
Expand Up @@ -273,13 +273,13 @@ config :archethic, ArchethicWeb.Endpoint,
config :archethic, :throttle,
by_ip_high: [
period: 1000,
limit: 500
limit: System.get_env("ARCHETHIC_THROTTLE_IP_HIGH", "500")
],
by_ip_low: [
period: 1000,
limit: 20
limit: System.get_env("ARCHETHIC_THROTTLE_IP_LOW", "20")
],
by_ip_and_path: [
period: 1000,
limit: 20
limit: System.get_env("ARCHETHIC_THROTTLE_IP_AND_PATH", "20")
]
6 changes: 3 additions & 3 deletions config/test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -176,13 +176,13 @@ config :archethic, ArchethicWeb.Endpoint,
config :archethic, :throttle,
by_ip_high: [
period: 1000,
limit: 5_000
limit: System.get_env("ARCHETHIC_THROTTLE_IP_HIGH", "5000")
],
by_ip_low: [
period: 1000,
limit: 5_000
limit: System.get_env("ARCHETHIC_THROTTLE_IP_LOW", "5000")
],
by_ip_and_path: [
period: 1000,
limit: 5_000
limit: System.get_env("ARCHETHIC_THROTTLE_IP_AND_PATH", "5000")
]
4 changes: 3 additions & 1 deletion lib/archethic/bootstrap/transaction_handler.ex
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ defmodule Archethic.Bootstrap.TransactionHandler do
defp await_confirmation(tx_address, [node | rest]) do
case P2P.send_message(node, %GetTransactionSummary{address: tx_address}) do
{:ok,
%TransactionSummaryMessage{transaction_summary: %TransactionSummary{address: ^tx_address}}} ->
%TransactionSummaryMessage{
transaction_summary: %TransactionSummary{address: ^tx_address}
}} ->
:ok

{:ok, %NotFound{}} ->
Expand Down
36 changes: 20 additions & 16 deletions lib/archethic/crypto.ex
Original file line number Diff line number Diff line change
Expand Up @@ -1141,22 +1141,26 @@ defmodule Archethic.Crypto do
"""
@spec get_root_ca_public_key(key()) :: binary()
def get_root_ca_public_key(<<curve::8, origin_id::8, _::binary>>) do
case Keyword.get(@certification_public_keys, ID.to_origin(origin_id)) do
nil ->
"no_key"

# Only for dev
[] ->
""

curves when is_list(curves) ->
case Keyword.get(curves, ID.to_curve(curve)) do
nil ->
"no_key"

public_key ->
public_key
end
if System.get_env("ARCHETHIC_NETWORK_TYPE") == "testnet" do
""
else
case Keyword.get(@certification_public_keys, ID.to_origin(origin_id)) do
nil ->
"no_key"

# Only for dev
[] ->
""

curves when is_list(curves) ->
case Keyword.get(curves, ID.to_curve(curve)) do
nil ->
"no_key"

public_key ->
public_key
end
end
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/archethic/db/embedded_impl/chain_index.ex
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ defmodule Archethic.DB.EmbeddedImpl.ChainIndex do
{:ok, %{db_path: db_path}}
end

def code_change("1.0.7", state, _extra) do
def code_change("1.0.6", state, _extra) do
## We start the unstarted LRU cache
cache_max_size = Application.get_env(:archethic, Archethic.DB.ChainIndex.MaxCacheSize)
LRU.start_link(@archetic_db_tx_index_cache, cache_max_size)
Expand Down
Loading

0 comments on commit b0a0d5d

Please sign in to comment.