Skip to content

Commit

Permalink
use distroless.dev/static base image (#1648)
Browse files Browse the repository at this point in the history
* closes #1621

* run hermes commands as root
  • Loading branch information
kirbyquerby committed Aug 10, 2022
1 parent 6ac473a commit e011a10
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 14 deletions.
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ RUN apk add --no-cache $PACKAGES
RUN CGO_ENABLED=0 make install

# Add to a distroless container
FROM gcr.io/distroless/cc:$IMG_TAG
FROM distroless.dev/static:$IMG_TAG
ARG IMG_TAG
COPY --from=gaiad-builder /go/bin/gaiad /usr/local/bin/
EXPOSE 26656 26657 1317 9090
USER 0

ENTRYPOINT ["gaiad", "start"]
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ endif
.PHONY: run-tests $(TEST_TARGETS)

docker-build-debug:
@docker build -t cosmos/gaiad-e2e --build-arg IMG_TAG=debug -f e2e.Dockerfile .
@docker build -t cosmos/gaiad-e2e -f e2e.Dockerfile .

# TODO: Push this to the Cosmos Dockerhub so we don't have to keep building it
# in CI.
Expand Down
2 changes: 1 addition & 1 deletion e2e.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ RUN apk add --no-cache $PACKAGES
RUN CGO_ENABLED=0 make install

# Add to a distroless container
FROM gcr.io/distroless/cc:$IMG_TAG
FROM distroless.dev/static:$IMG_TAG
ARG IMG_TAG
COPY --from=gaiad-builder /go/bin/gaiad /usr/local/bin/
EXPOSE 26656 26657 1317 9090
Expand Down
7 changes: 5 additions & 2 deletions tests/e2e/e2e_setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"io/ioutil"
"net/http"
"os"
"os/exec"
"path"
"path/filepath"
"strconv"
Expand Down Expand Up @@ -245,7 +246,7 @@ func (s *IntegrationTestSuite) initGenesis(c *chain) {
bz, err = tmjson.MarshalIndent(genDoc, "", " ")
s.Require().NoError(err)

// write the updated genesis file to each validator
// write the updated genesis file to each validator.
for _, val := range c.validators {
err = writeFile(filepath.Join(val.configDir(), "config", "genesis.json"), bz)
s.Require().NoError(err)
Expand Down Expand Up @@ -308,11 +309,13 @@ func (s *IntegrationTestSuite) runValidators(c *chain, portOffset int) {
Name: val.instanceName(),
NetworkID: s.dkrNet.Network.ID,
Mounts: []string{
fmt.Sprintf("%s/:/root/.gaia", val.configDir()),
fmt.Sprintf("%s/:/home/nonroot/.gaia", val.configDir()),
},
Repository: "cosmos/gaiad-e2e",
}

s.Require().NoError(exec.Command("chmod", "-R", "0777", val.configDir()).Run())

// expose the first validator for debugging and communication
if val.index == 0 {
runOpts.PortBindings = map[docker.Port][]docker.PortBinding{
Expand Down
12 changes: 6 additions & 6 deletions tests/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func (s *IntegrationTestSuite) TestSendTokensFromNewGovAccount() {
proposalCounter++

s.T().Logf("Submitting Gov Proposal: Sending Tokens from Gov Module to Recipient")
s.submitNewGovProposal(chainAAPIEndpoint, sender, proposalCounter, "/root/.gaia/config/proposal_2.json")
s.submitNewGovProposal(chainAAPIEndpoint, sender, proposalCounter, "/home/nonroot/.gaia/config/proposal_2.json")
s.T().Logf("Depositing Gov Proposal: Sending Tokens from Gov Module to Recipient")
s.depositGovProposal(chainAAPIEndpoint, sender, proposalCounter)
s.T().Logf("Voting Gov Proposal: Sending Tokens from Gov Module to Recipient")
Expand Down Expand Up @@ -158,14 +158,14 @@ func (s *IntegrationTestSuite) TestGovSoftwareUpgrade() {
s.writeGovUpgradeSoftwareProposal(s.chainA, proposalHeight)

s.T().Logf("Submitting Gov Proposal: Software Upgrade")
s.submitNewGovProposal(chainAAPIEndpoint, sender, proposalCounter, "/root/.gaia/config/proposal_3.json")
s.submitNewGovProposal(chainAAPIEndpoint, sender, proposalCounter, "/home/nonroot/.gaia/config/proposal_3.json")
s.T().Logf("Depositing Gov Proposal: Software Upgrade")
s.depositGovProposal(chainAAPIEndpoint, sender, proposalCounter)
s.T().Logf("Weighted Voting Gov Proposal: Software Upgrade")
s.voteGovProposal(chainAAPIEndpoint, sender, proposalCounter, "yes=0.8,no=0.1,abstain=0.05,no_with_veto=0.05", true)

s.verifyChainHaltedAtUpgradeHeight(s.chainA, 0, proposalHeight)
s.T().Logf("Successfully halted chain at height %d", proposalHeight)
s.T().Logf("Successfully halted chain at height %d", proposalHeight)

s.TearDownSuite()

Expand Down Expand Up @@ -201,14 +201,14 @@ func (s *IntegrationTestSuite) TestGovCancelSoftwareUpgrade() {
s.writeGovUpgradeSoftwareProposal(s.chainA, proposalHeight)

s.T().Logf("Submitting Gov Proposal: Software Upgrade")
s.submitNewGovProposal(chainAAPIEndpoint, sender, proposalCounter, "/root/.gaia/config/proposal_3.json")
s.submitNewGovProposal(chainAAPIEndpoint, sender, proposalCounter, "/home/nonroot/.gaia/config/proposal_3.json")
s.depositGovProposal(chainAAPIEndpoint, sender, proposalCounter)
s.voteGovProposal(chainAAPIEndpoint, sender, proposalCounter, "yes", false)

proposalCounter++

s.T().Logf("Submitting Gov Proposal: Cancel Software Upgrade")
s.submitNewGovProposal(chainAAPIEndpoint, sender, proposalCounter, "/root/.gaia/config/proposal_4.json")
s.submitNewGovProposal(chainAAPIEndpoint, sender, proposalCounter, "/home/nonroot/.gaia/config/proposal_4.json")
s.depositGovProposal(chainAAPIEndpoint, sender, proposalCounter)
s.voteGovProposal(chainAAPIEndpoint, sender, proposalCounter, "yes", false)

Expand Down Expand Up @@ -247,7 +247,7 @@ func (s *IntegrationTestSuite) fundCommunityPool(chainAAPIEndpoint, sender strin

func (s *IntegrationTestSuite) submitLegacyProposalFundGovAccount(chainAAPIEndpoint, sender string, proposalId int) {
s.Run("submit_legacy_community_spend_proposal_to_fund_gov_acct", func() {
s.execGovSubmitLegacyGovProposal(s.chainA, 0, chainAAPIEndpoint, sender, "/root/.gaia/config/proposal.json", fees.String(), "community-pool-spend")
s.execGovSubmitLegacyGovProposal(s.chainA, 0, chainAAPIEndpoint, sender, "/home/nonroot/.gaia/config/proposal.json", fees.String(), "community-pool-spend")

s.Require().Eventually(
func() bool {
Expand Down
6 changes: 3 additions & 3 deletions tests/e2e/e2e_util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func (s *IntegrationTestSuite) sendMsgSend(c *chain, valIdx int, from, to, amt,
AttachStdout: true,
AttachStderr: true,
Container: s.valResources[c.id][valIdx].Container.ID,
User: "root",
User: "nonroot",
Cmd: []string{
"gaiad",
"tx",
Expand Down Expand Up @@ -337,7 +337,7 @@ func (s *IntegrationTestSuite) executeGaiaTxCommand(ctx context.Context, c *chai
AttachStdout: true,
AttachStderr: true,
Container: s.valResources[c.id][valIdx].Container.ID,
User: "root",
User: "nonroot",
Cmd: gaiaCommand,
})
s.Require().NoError(err)
Expand Down Expand Up @@ -426,7 +426,7 @@ func (s *IntegrationTestSuite) getLatestBlockHeight(c *chain, valIdx int) int {
AttachStdout: true,
AttachStderr: true,
Container: s.valResources[c.id][valIdx].Container.ID,
User: "root",
User: "nonroot",
Cmd: []string{"gaiad", "status"},
})
s.Require().NoError(err)
Expand Down

0 comments on commit e011a10

Please sign in to comment.