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

Add automatic docker image build & push on release #224

Closed
wants to merge 11 commits into from
64 changes: 64 additions & 0 deletions .github/workflows/build-push-docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: Docker Image Build and Push
on:
push:
tags:
- '*'

jobs:
build:
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Set version
id: vars
run: echo ::set-output name=tag::${GITHUB_REF#refs/*/}

- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: |
atarrio/powpeg-node
ghcr.io/atarrio/powpeg-node
#rsk/powpeg-node
#ghcr.io/rsksmart/powpeg-node
tags: |
type=ref,event=tag
type=edge
# This is used for generating IRIS-3 out of IRIS-3.x.y.
type=match,pattern=(\w+-\d+)\.\d+\.\d+.*,group=1

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
driver: docker

- name: Build Docker Image
uses: docker/build-push-action@v5
with:
context: .
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: RSK_RELEASE=${{ steps.vars.outputs.tag }}

- name: DockerHub login
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: GitHub container registry login
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Push Images
uses: docker/build-push-action@v5
with:
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
37 changes: 37 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
FROM openjdk:11-jdk-slim-buster AS build

ARG RSK_RELEASE
ENV RSK_VERSION $RSK_RELEASE
ARG DEBIAN_FRONTEND=noninteractive

RUN apt-get update -y && \
apt-get install -y git curl gnupg

RUN useradd -ms /bin/bash rsk
USER rsk

WORKDIR /home/rsk
COPY --chown=rsk:rsk . ./

RUN gpg --keyserver https://secchannel.rsk.co/SUPPORT.asc --recv-keys 1DC9157991323D23FD37BAA7A6DBEAC640C5A14B && \
gpg --verify --output SHA256SUMS SHA256SUMS.asc && \
sha256sum --check SHA256SUMS && \
./configure.sh && \
./gradlew --no-daemon clean build -x test && \
cp "build/libs/federate-node-$RSK_VERSION-all.jar" rsk.jar

FROM openjdk:11-jre-slim-buster
LABEL org.opencontainers.image.authors="[email protected]"

RUN useradd -ms /sbin/nologin -d /var/lib/rsk rsk
USER rsk

WORKDIR /var/lib/rsk
COPY --from=build --chown=rsk:rsk /home/rsk/rsk.jar ./

ENV DEFAULT_JVM_OPTS="-Xss4M"
ENV RSKJ_SYS_PROPS="-Dlogback.configurationFile='/etc/rsk/logback.xml' -Drsk.conf.file=/etc/rsk/node.conf"
ENV RSKJ_CLASS=co.rsk.federate.FederateRunner
ENV RSKJ_OPTS=""

ENTRYPOINT ["/bin/sh", "-c", "java $DEFAULT_JVM_OPTS $RSKJ_SYS_PROPS -cp rsk.jar $RSKJ_CLASS $RSKJ_OPTS \"${@}\"", "--"]
4 changes: 2 additions & 2 deletions src/main/java/co/rsk/federate/BtcToRskClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
import co.rsk.net.NodeBlockProcessor;
import co.rsk.panic.PanicProcessor;
import co.rsk.peg.BridgeUtils;
import co.rsk.peg.Federation;
import co.rsk.peg.FederationMember;
import co.rsk.peg.PegUtilsLegacy;
import co.rsk.peg.federation.Federation;
import co.rsk.peg.federation.FederationMember;
import co.rsk.peg.PeginInformation;
import co.rsk.peg.btcLockSender.BtcLockSender.TxSenderAddressType;
import co.rsk.peg.btcLockSender.BtcLockSenderProvider;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/co/rsk/federate/FedNodeRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@
import co.rsk.federate.signing.hsm.message.SignerMessageBuilderFactory;
import co.rsk.federate.signing.hsm.requirements.AncestorBlockUpdater;
import co.rsk.federate.signing.hsm.requirements.ReleaseRequirementsEnforcer;
import co.rsk.peg.Federation;
import co.rsk.peg.FederationMember;
import co.rsk.peg.federation.Federation;
import co.rsk.peg.federation.FederationMember;
import co.rsk.peg.btcLockSender.BtcLockSenderProvider;
import co.rsk.peg.pegininstructions.PeginInstructionsProvider;
import org.bitcoinj.core.Context;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/co/rsk/federate/FederationProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
package co.rsk.federate;

import co.rsk.bitcoinj.core.Address;
import co.rsk.peg.Federation;
import co.rsk.peg.federation.Federation;

import java.util.List;
import java.util.Optional;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,16 @@

import co.rsk.bitcoinj.core.Address;
import co.rsk.bitcoinj.core.BtcECKey;
import co.rsk.bitcoinj.core.NetworkParameters;
import co.rsk.config.BridgeConstants;
import co.rsk.peg.Federation;
import co.rsk.peg.StandardMultisigFederation;
import co.rsk.peg.LegacyErpFederation;
import co.rsk.peg.P2shErpFederation;
import co.rsk.peg.FederationMember;
import co.rsk.peg.federation.*;
import org.ethereum.config.blockchain.upgrades.ActivationConfig;
import org.ethereum.crypto.ECKey;

import java.time.Instant;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

import static org.ethereum.config.blockchain.upgrades.ConsensusRule.RSKIP123;

/**
Expand Down Expand Up @@ -76,13 +73,10 @@ public Federation getActiveFederation() {
}
Instant creationTime = federatorSupport.getFederationCreationTime();
long creationBlockNumber = federatorSupport.getFederationCreationBlockNumber();
NetworkParameters btcParams = federatorSupport.getBtcParams();
FederationArgs federationArgs = new FederationArgs(members, creationTime, creationBlockNumber, btcParams);

Federation initialFederation = new StandardMultisigFederation(
members,
creationTime,
creationBlockNumber,
federatorSupport.getBtcParams()
);
Federation initialFederation = FederationFactory.buildStandardMultiSigFederation(federationArgs);

return getExpectedFederation(initialFederation, getActiveFederationAddress());
}
Expand Down Expand Up @@ -126,13 +120,10 @@ public Optional<Federation> getRetiringFederation() {

Instant creationTime = federatorSupport.getRetiringFederationCreationTime();
long creationBlockNumber = federatorSupport.getRetiringFederationCreationBlockNumber();
NetworkParameters btcParams = federatorSupport.getBtcParams();
FederationArgs federationArgs = new FederationArgs(members, creationTime, creationBlockNumber, btcParams);

Federation initialFederation = new StandardMultisigFederation(
members,
creationTime,
creationBlockNumber,
federatorSupport.getBtcParams()
);
Federation initialFederation = FederationFactory.buildStandardMultiSigFederation(federationArgs);

return Optional.of(getExpectedFederation(initialFederation, retiringFederationAddress));
}
Expand All @@ -158,32 +149,27 @@ private Federation getExpectedFederation(Federation initialFederation, Address e
if (initialFederation.getAddress().equals(expectedFederationAddress)) {
return initialFederation;
}

// If addresses do not match build an ERP federation
Federation erpFederation = new LegacyErpFederation(
initialFederation.getMembers(),
initialFederation.getCreationTime(),
initialFederation.getCreationBlockNumber(),
federatorSupport.getBtcParams(),
bridgeConstants.getErpFedPubKeysList(),
bridgeConstants.getErpFedActivationDelay(),
federatorSupport.getConfigForBestBlock()
);

if (erpFederation.getAddress().equals(expectedFederationAddress)) {
return erpFederation;
List<FederationMember> members = initialFederation.getMembers();
Instant creationTime = initialFederation.getCreationTime();
long creationBlockNumber = initialFederation.getCreationBlockNumber();
NetworkParameters btcParams = federatorSupport.getBtcParams();
List<BtcECKey> erpPubKeys = bridgeConstants.getErpFedPubKeysList();
long activationDelay = bridgeConstants.getErpFedActivationDelay();
ActivationConfig.ForBlock activations = federatorSupport.getConfigForBestBlock();

FederationArgs federationArgs =
new FederationArgs(members, creationTime, creationBlockNumber, btcParams);

// If addresses match build a Non-Standard ERP federation
ErpFederation nonStandardErpFederation =
FederationFactory.buildNonStandardErpFederation(federationArgs, erpPubKeys, activationDelay, activations);

if (nonStandardErpFederation.getAddress().equals(expectedFederationAddress)) {
return nonStandardErpFederation;
}

// Finally, try building a P2SH ERP federation
return new P2shErpFederation(
initialFederation.getMembers(),
initialFederation.getCreationTime(),
initialFederation.getCreationBlockNumber(),
federatorSupport.getBtcParams(),
bridgeConstants.getErpFedPubKeysList(),
bridgeConstants.getErpFedActivationDelay(),
federatorSupport.getConfigForBestBlock()
);
return FederationFactory.buildP2shErpFederation(federationArgs, erpPubKeys, activationDelay);

// TODO: what if no federation built matches the expected address?
// It could mean that there is a different type of federation in the Bridge that we are not considering here
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/co/rsk/federate/FederationWatcher.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package co.rsk.federate;

import co.rsk.bitcoinj.core.Address;
import co.rsk.peg.Federation;
import co.rsk.peg.federation.Federation;
import org.ethereum.core.TransactionReceipt;
import org.ethereum.facade.Ethereum;
import org.ethereum.listener.EthereumListenerAdapter;
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/co/rsk/federate/FederatorSupport.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,13 @@
import co.rsk.federate.config.FedNodeSystemProperties;
import co.rsk.federate.signing.ECDSASigner;
import co.rsk.peg.Bridge;
import co.rsk.peg.BridgeMethods;
import co.rsk.peg.FederationMember;
import co.rsk.peg.federation.FederationMember;
import co.rsk.peg.StateForFederator;
import org.bitcoinj.core.PartialMerkleTree;
import org.bitcoinj.core.PeerAddress;
import org.bitcoinj.core.Sha256Hash;
import org.ethereum.config.blockchain.upgrades.ActivationConfig;
import org.ethereum.core.Blockchain;
import org.ethereum.core.CallTransaction;
import org.ethereum.crypto.ECKey;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package co.rsk.federate.bitcoin;

import co.rsk.peg.Federation;
import co.rsk.peg.federation.Federation;
import org.bitcoinj.core.*;
import org.bitcoinj.core.listeners.NewBestBlockListener;
import org.bitcoinj.store.BlockStoreException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import co.rsk.federate.FederatorSupport;
import co.rsk.federate.adapter.ThinConverter;
import co.rsk.peg.BridgeBtcWallet;
import co.rsk.peg.Federation;
import co.rsk.peg.PegUtilsLegacy;
import co.rsk.peg.federation.Federation;
import co.rsk.peg.PeginInformation;
import co.rsk.peg.btcLockSender.BtcLockSenderProvider;
import co.rsk.peg.pegininstructions.PeginInstructionsException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
import co.rsk.peg.Bridge;
import co.rsk.peg.BridgeEvents;
import co.rsk.peg.BridgeUtils;
import co.rsk.peg.Federation;
import co.rsk.peg.ErpFederation;
import co.rsk.peg.federation.Federation;
import co.rsk.peg.federation.ErpFederation;
import co.rsk.peg.StateForFederator;
import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -352,7 +352,7 @@ protected void validateTxCanBeSigned(BtcTransaction btcTx) throws FederatorAlrea
observedFederations.stream()
.forEach(f -> logger.trace("[validateTxCanBeSigned] federation p2sh redeem script {}", f.getRedeemScript()));
List<Federation> spendingFedFilter = observedFederations.stream()
.filter(f -> (f instanceof ErpFederation ? ((ErpFederation) f).getStandardRedeemScript() : f.getRedeemScript()).equals(standardRedeemScript)).collect(Collectors.toList());
.filter(f -> (extractDefaultRedeemScript(f)).equals(standardRedeemScript)).collect(Collectors.toList());
logger.debug("[validateTxCanBeSigned] spendingFedFilter size {}", spendingFedFilter.size());
if (spendingFedFilter.isEmpty()) {
String message = String.format(
Expand Down Expand Up @@ -451,6 +451,13 @@ protected Script extractStandardRedeemScript(Script redeemScript) {
return parser.extractStandardRedeemScript();
}

private Script extractDefaultRedeemScript(Federation federation) {
if (federation instanceof ErpFederation) {
return ((ErpFederation) federation).getDefaultRedeemScript();
}
return federation.getRedeemScript();
}

protected Script getRedeemScriptFromInput(TransactionInput txInput) {
Script inputScript = txInput.getScriptSig();
List<ScriptChunk> chunks = inputScript.getChunks();
Expand All @@ -464,7 +471,8 @@ protected Federation getSpendingFederation(BtcTransaction btcTx) {
Script redeemScript = extractStandardRedeemScript(getRedeemScriptFromInput(firstInput));

List<Federation> spendingFedFilter = observedFederations.stream()
.filter(f -> (f instanceof ErpFederation ? ((ErpFederation) f).getStandardRedeemScript() : f.getRedeemScript()).equals(redeemScript)).collect(Collectors.toList());
.filter(f -> (extractDefaultRedeemScript(f)).equals(redeemScript)).collect(Collectors.toList());


return spendingFedFilter.get(0);
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/co/rsk/federate/BtcToRskClientBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import co.rsk.federate.io.BtcToRskClientFileData;
import co.rsk.federate.io.BtcToRskClientFileReadResult;
import co.rsk.federate.io.BtcToRskClientFileStorage;
import co.rsk.peg.Federation;
import co.rsk.peg.federation.Federation;
import co.rsk.peg.btcLockSender.BtcLockSenderProvider;
import co.rsk.peg.pegininstructions.PeginInstructionsException;
import co.rsk.peg.pegininstructions.PeginInstructionsProvider;
Expand Down
5 changes: 3 additions & 2 deletions src/test/java/co/rsk/federate/BtcToRskClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@
import co.rsk.federate.mock.SimpleBtcTransaction;
import co.rsk.federate.mock.SimpleFederatorSupport;
import co.rsk.net.NodeBlockProcessor;
import co.rsk.peg.Federation;
import co.rsk.peg.FederationMember;
import co.rsk.peg.BridgeUtils;
import co.rsk.peg.PegUtilsLegacy;
import co.rsk.peg.federation.Federation;
import co.rsk.peg.federation.FederationMember;
import co.rsk.peg.btcLockSender.BtcLockSender;
import co.rsk.peg.btcLockSender.BtcLockSender.TxSenderAddressType;
import co.rsk.peg.btcLockSender.BtcLockSenderProvider;
Expand Down
Loading