Skip to content

Commit

Permalink
Fix docker push test (#1138)
Browse files Browse the repository at this point in the history
* refactor docker yml and scripts

* enable pr for test

* fix path

* fix path

* rename img id

* try simpler name

* use -a

* test tag

* remove test steps

* remove avalanchego from image id
  • Loading branch information
ceyonur authored Apr 8, 2024
1 parent 004a1d2 commit 4bdb91e
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 40 deletions.
10 changes: 6 additions & 4 deletions .github/workflows/publish_docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ jobs:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v4
- run: echo ${{ secrets.docker_pass }} | docker login --username ${{ secrets.docker_username }} --password-stdin
shell: bash
- run: CURRENT_BRANCH=${{ github.head_ref || github.ref_name }} PUSH_DOCKER_IMAGE=true ./scripts/build_image.sh
shell: bash
- name: Publish image to Dockerhub
env:
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_PASS: ${{ secrets.DOCKER_PASS }}
DOCKER_REPO: "avaplatform/subnet-evm"
run: .github/workflows/publish_docker_image.sh
30 changes: 30 additions & 0 deletions .github/workflows/publish_docker_image.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env bash

set -o errexit
set -o nounset
set -o pipefail

# If this is not a trusted build (Docker Credentials are not set)
if [[ -z "$DOCKER_USERNAME" ]]; then
exit 0;
fi

# Avalanche root directory
SUBNET_EVM_PATH=$( cd "$( dirname "${BASH_SOURCE[0]}" )"; cd ../.. && pwd )

# Load the versions
source "$SUBNET_EVM_PATH"/scripts/versions.sh

# Buld the docker image
source "$SUBNET_EVM_PATH"/scripts/build_docker_image.sh

if [[ $CURRENT_BRANCH == "master" ]]; then
echo "Tagging current image as $DOCKERHUB_REPO:latest"
docker tag "$DOCKERHUB_REPO:$BUILD_IMAGE_ID" "$DOCKERHUB_REPO:latest"
fi

echo "Pushing $DOCKERHUB_REPO:$BUILD_IMAGE_ID"

echo "$DOCKER_PASS" | docker login --username "$DOCKER_USERNAME" --password-stdin

docker push -a "$DOCKERHUB_REPO"
21 changes: 21 additions & 0 deletions scripts/build_docker_image.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env bash

set -euo pipefail

# Directory above this script
SUBNET_EVM_PATH=$( cd "$( dirname "${BASH_SOURCE[0]}" )"; cd .. && pwd )

# Load the constants
source "$SUBNET_EVM_PATH"/scripts/constants.sh

# Load the versions
source "$SUBNET_EVM_PATH"/scripts/versions.sh

# WARNING: this will use the most recent commit even if there are un-committed changes present
BUILD_IMAGE_ID=${BUILD_IMAGE_ID:-"${CURRENT_BRANCH}"}

echo "Building Docker Image: $DOCKERHUB_REPO:$BUILD_IMAGE_ID based of AvalancheGo@$AVALANCHE_VERSION"
docker build -t "$DOCKERHUB_REPO:$BUILD_IMAGE_ID" "$SUBNET_EVM_PATH" -f "$SUBNET_EVM_PATH/Dockerfile" \
--build-arg AVALANCHE_VERSION="$AVALANCHE_VERSION" \
--build-arg SUBNET_EVM_COMMIT="$SUBNET_EVM_COMMIT" \
--build-arg CURRENT_BRANCH="$CURRENT_BRANCH"
33 changes: 0 additions & 33 deletions scripts/build_image.sh

This file was deleted.

6 changes: 3 additions & 3 deletions scripts/constants.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ set -euo pipefail
GOPATH="$(go env GOPATH)"

# Avalabs docker hub
DOCKERHUB_REPO="avaplatform/subnet-evm"
# avaplatform/avalanchego - defaults to local as to avoid unintentional pushes
# You should probably set it - export DOCKER_REPO='avaplatform/subnet-evm'
DOCKERHUB_REPO=${DOCKER_REPO:-"subnet-evm"}

# if this isn't a git repository (say building from a release), don't set our git constants.
if [ ! -d .git ]; then
CURRENT_BRANCH=""
SUBNET_EVM_COMMIT=""
SUBNET_EVM_COMMIT_ID=""
else
# Current branch
CURRENT_BRANCH=${CURRENT_BRANCH:-$(git describe --tags --exact-match 2>/dev/null || git symbolic-ref -q --short HEAD || git rev-parse --short HEAD || :)}
Expand All @@ -25,7 +26,6 @@ else
# Use an abbreviated version of the full commit to tag the image.
# WARNING: this will use the most recent commit even if there are un-committed changes present
SUBNET_EVM_COMMIT="$(git --git-dir="$SUBNET_EVM_PATH/.git" rev-parse HEAD || :)"
SUBNET_EVM_COMMIT_ID="${SUBNET_EVM_COMMIT::8}"
fi

echo "Using branch: ${CURRENT_BRANCH}"
Expand Down

0 comments on commit 4bdb91e

Please sign in to comment.