Skip to content

Commit

Permalink
Use Env variables consistently.
Browse files Browse the repository at this point in the history
- use workflow env: per step
- Rename DOCKER_HUB to DOCKER_REGISTRY
- Login to ghcr.io in the same way as dockerhub
  • Loading branch information
gr0vity-dev committed Jun 22, 2023
1 parent 230fcf1 commit 7ea2a1b
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 35 deletions.
30 changes: 20 additions & 10 deletions .github/workflows/artifacts_build_deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,11 @@ jobs:
- name: Fetch Deps
run: ci/actions/osx/install_deps.sh
- name: Build Artifact
run: NETWORK=${{ matrix.network }} CI_TAG="${{ needs.prepare_build.outputs.CI_TAG }}" CI_VERSION_PRE_RELEASE="${{ needs.prepare_build.outputs.CI_VERSION_PRE_RELEASE }}" ci/build-deploy.sh "/tmp/qt/lib/cmake/Qt5";
run: ci/build-deploy.sh "/tmp/qt/lib/cmake/Qt5";
env:
NETWORK: ${{ matrix.network }}
CI_TAG: "${{ needs.prepare_build.outputs.CI_TAG }}"
CI_VERSION_PRE_RELEASE: "${{ needs.prepare_build.outputs.CI_VERSION_PRE_RELEASE }}"
- name: Deploy Artifact
run: ci/actions/deploy.sh
env:
Expand Down Expand Up @@ -166,24 +170,30 @@ jobs:
COMPILER: gcc
run: ci/actions/linux/install_deps.sh
- name: Build Docker
run: NETWORK=${{ matrix.network }} CI_TAG=${{ needs.prepare_build.outputs.CI_TAG }} CI_VERSION_PRE_RELEASE=${{ needs.prepare_build.outputs.CI_VERSION_PRE_RELEASE }} ci/actions/linux/docker-build.sh
run: ci/actions/linux/docker-build.sh
env:
NETWORK: ${{ matrix.network }}
CI_TAG: ${{ needs.prepare_build.outputs.CI_TAG }}
CI_VERSION_PRE_RELEASE: ${{ needs.prepare_build.outputs.CI_VERSION_PRE_RELEASE }}
- name: Check if secrets.DOCKER_PASSWORD exists
run: echo "DOCKER_PASSWORD_EXISTS=${{ secrets.DOCKER_PASSWORD != '' }}" >> $GITHUB_ENV
- name: Deploy Docker Hub
if: env.DOCKER_PASSWORD_EXISTS == 'true'
run: CI_TAG=${{ needs.prepare_build.outputs.CI_TAG }} ci/actions/linux/docker-deploy.sh
run: ci/actions/linux/docker-deploy.sh
env:
DOCKER_HUB: ${{ secrets.DOCKER_HUB }}
CI_TAG: ${{ needs.prepare_build.outputs.CI_TAG }}
NETWORK: ${{ matrix.network }}
DOCKER_REGISTRY: ${{ secrets.DOCKER_HUB }}
DOCKER_USER: ${{ secrets.DOCKER_USER }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
- name: Login to ghcr.io
uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a #v2.1.0
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Deploy Docker (ghcr.io)
run: ci/actions/linux/ghcr-deploy.sh
env:
CI_TAG: ${{ needs.prepare_build.outputs.CI_TAG }}
NETWORK: ${{ matrix.network }}
DOCKER_REGISTRY: ghcr.io
DOCKER_USER: ${{ github.repository_owner }}
DOCKER_PASSWORD: ${{ secrets.GITHUB_TOKEN }}

windows_job:
needs: prepare_build
Expand Down
10 changes: 4 additions & 6 deletions .github/workflows/develop_branch_dockers_deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,12 @@ jobs:
submodules: "recursive"
- name: Fetch Deps
run: ci/actions/linux/install_deps.sh
- name: Login to ghcr.io
uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a #v2.1.0
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Deploy Docker (ghcr.io)
run: ci/actions/linux/ghcr-deploy-env.sh
env:
DOCKER_REGISTRY: ghcr.io
DOCKER_USER: ${{ github.repository_owner }}
DOCKER_PASSWORD: ${{ secrets.GITHUB_TOKEN }}
- name: Check if secrets.DOCKER_PASSWORD exists
run: echo "DOCKER_PASSWORD_EXISTS=${{ secrets.DOCKER_PASSWORD != '' }}" >> $GITHUB_ENV
- name: Deploy Docker (nanocurrency/nano-env)
Expand Down
43 changes: 24 additions & 19 deletions ci/actions/linux/docker-impl/docker-common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set -a

scripts="$PWD/ci"
CI_BRANCH=$(git rev-parse --abbrev-ref HEAD)
DOCKER_HUB="${DOCKER_HUB:-nanocurrency}"
DOCKER_REGISTRY="${DOCKER_REGISTRY:-nanocurrency}"
DOCKER_USER="${DOCKER_USER:-nanoreleaseteam}"
tags=()

Expand All @@ -30,8 +30,8 @@ elif [[ "$NETWORK" = "TEST" ]]; then
network="test"
fi

docker_image_name="${DOCKER_HUB}/nano${network_tag_suffix}"
ghcr_image_name="ghcr.io/${GITHUB_REPOSITORY}/nano${network_tag_suffix}"
docker_image_name="${DOCKER_REGISTRY}/nano${network_tag_suffix}"
ghcr_image_name="${DOCKER_REGISTRY}/${GITHUB_REPOSITORY}/nano${network_tag_suffix}"

docker_build()
{
Expand Down Expand Up @@ -78,35 +78,37 @@ docker_deploy()
{
docker_login "$DOCKER_USER" "$DOCKER_PASSWORD"
if [[ "$NETWORK" = "LIVE" ]]; then
deploy_tags "$DOCKER_HUB" "env|ghcr.io|none|latest"
deploy_tags "${DOCKER_REGISTRY}" "env|ghcr.io|none|latest"
else
deploy_tags "$DOCKER_HUB" "env|ghcr.io|none"
deploy_tags "${DOCKER_REGISTRY}" "env|ghcr.io|none"
fi
}

ghcr_deploy()
{
deploy_tags "ghcr.io/${GITHUB_REPOSITORY}" "env|none"
{
docker_login "$DOCKER_USER" "$DOCKER_PASSWORD"
deploy_tags "${DOCKER_REGISTRY}/${GITHUB_REPOSITORY}" "env|none"
}

ghcr_deploy_env()
{
docker_deploy_env()
{
docker_login "$DOCKER_USER" "$DOCKER_PASSWORD"
local images=(
"ghcr.io/${GITHUB_REPOSITORY}/nano-env:base"
"ghcr.io/${GITHUB_REPOSITORY}/nano-env:gcc"
"ghcr.io/${GITHUB_REPOSITORY}/nano-env:clang"
"ghcr.io/${GITHUB_REPOSITORY}/nano-env:rhel"
"${DOCKER_REGISTRY}/nano-env:base"
"${DOCKER_REGISTRY}/nano-env:gcc"
"${DOCKER_REGISTRY}/nano-env:clang"
)
deploy_env_images "${images[@]}"
deploy_env_images "${images[@]}"
}

docker_deploy_env()
ghcr_deploy_env()
{
docker_login "$DOCKER_USER" "$DOCKER_PASSWORD"
docker_login "$DOCKER_USER" "$DOCKER_PASSWORD"
local images=(
"$DOCKER_HUB/nano-env:base"
"$DOCKER_HUB/nano-env:gcc"
"$DOCKER_HUB/nano-env:clang"
"${DOCKER_REGISTRY}/${GITHUB_REPOSITORY}/nano-env:base"
"${DOCKER_REGISTRY}/${GITHUB_REPOSITORY}/nano-env:gcc"
"${DOCKER_REGISTRY}/${GITHUB_REPOSITORY}/nano-env:clang"
"${DOCKER_REGISTRY}/${GITHUB_REPOSITORY}/nano-env:rhel"
)
deploy_env_images "${images[@]}"
}
Expand Down Expand Up @@ -147,6 +149,9 @@ deploy_tags()
local exclude_pattern=$2
local tags=$(docker images --format '{{.Repository}}:{{.Tag }}' | grep "$repo" | grep -vE "$exclude_pattern")

#Debug list all tags
docker images --format '{{.Repository}}:{{.Tag }}'

for tag in $tags; do
push_docker_image "$tag"
done
Expand Down

0 comments on commit 7ea2a1b

Please sign in to comment.