Skip to content

Commit

Permalink
setting global env variables
Browse files Browse the repository at this point in the history
  • Loading branch information
pacostas authored and mhdawson committed Jan 20, 2025
1 parent fdf1871 commit a9bcbd9
Showing 1 changed file with 38 additions and 38 deletions.
76 changes: 38 additions & 38 deletions .github/workflows/push-buildpackage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,22 @@ on:
release:
types:
- published

env:
REGISTRIES_FILENAME: "registries.json"

jobs:
push:
name: Push
runs-on: ubuntu-22.04
env:
GCR_REGISTRY: "gcr.io"
GCR_PASSWORD: ${{ secrets.GCR_PUSH_BOT_JSON_KEY }}
GCR_USERNAME: "_json_key"
DOCKERHUB_REGISTRY: docker.io
DOCKERHUB_USERNAME: ${{ secrets.PAKETO_BUILDPACKS_DOCKERHUB_USERNAME }}
DOCKERHUB_PASSWORD: ${{ secrets.PAKETO_BUILDPACKS_DOCKERHUB_PASSWORD }}

steps:

- name: Checkout
Expand Down Expand Up @@ -45,17 +54,15 @@ jobs:
- name: Parse Configs
id: parse_configs
run: |
registries_filename="${{ env.REGISTRIES_FILENAME }}"
push_to_dockerhub=true
push_to_gcr=true
if [[ -f $registries_filename ]]; then
if jq 'has("dockerhub")' $registries_filename > /dev/null; then
push_to_dockerhub=$(jq '.dockerhub' $registries_filename)
if [[ -f $REGISTRIES_FILENAME ]]; then
if jq 'has("dockerhub")' $REGISTRIES_FILENAME > /dev/null; then
push_to_dockerhub=$(jq '.dockerhub' $REGISTRIES_FILENAME)
fi
if jq 'has("GCR")' $registries_filename > /dev/null; then
push_to_gcr=$(jq '.GCR' $registries_filename)
if jq 'has("GCR")' $REGISTRIES_FILENAME > /dev/null; then
push_to_gcr=$(jq '.GCR' $REGISTRIES_FILENAME)
fi
fi
Expand All @@ -74,53 +81,46 @@ jobs:
- name: Docker login docker.io
uses: docker/login-action@v3
with:
username: ${{ secrets.PAKETO_BUILDPACKS_DOCKERHUB_USERNAME }}
password: ${{ secrets.PAKETO_BUILDPACKS_DOCKERHUB_PASSWORD }}
registry: docker.io
username: ${{ env.DOCKERHUB_USERNAME }}
password: ${{ env.DOCKERHUB_PASSWORD }}
registry: ${{ env.DOCKERHUB_REGISTRY }}

- name: Docker login gcr.io
uses: docker/login-action@v3
if: ${{ steps.parse_configs.outputs.push_to_gcr == 'true' }}
with:
username: ${{ env.GCR_USERNAME }}
password: ${{ env.GCR_PASSWORD }}
registry: ${{ env.GCR_REGISTRY }}

- name: Push to DockerHub
if: ${{ steps.parse_configs.outputs.push_to_dockerhub == 'true' }}
id: push
env:
DOCKERHUB_USERNAME: ${{ secrets.PAKETO_BUILDPACKS_DOCKERHUB_USERNAME }}
DOCKERHUB_PASSWORD: ${{ secrets.PAKETO_BUILDPACKS_DOCKERHUB_PASSWORD }}
GITHUB_REPOSITORY_OWNER: ${{ github.repository_owner }}
run: |
REPOSITORY="${GITHUB_REPOSITORY_OWNER/-/}/${GITHUB_REPOSITORY#${GITHUB_REPOSITORY_OWNER}/}" # translates 'paketo-buildpacks/bundle-install' to 'paketobuildpacks/bundle-install'
IMAGE="index.docker.io/${REPOSITORY}"
IMAGE="${GITHUB_REPOSITORY_OWNER/-/}/${GITHUB_REPOSITORY#${GITHUB_REPOSITORY_OWNER}/}" # translates 'paketo-buildpacks/bundle-install' to 'paketobuildpacks/bundle-install'
echo "${DOCKERHUB_PASSWORD}" | sudo skopeo login --username "${DOCKERHUB_USERNAME}" --password-stdin ${DOCKERHUB_REGISTRY}
./scripts/publish.sh \
--buildpack-archive ./buildpack.tgz \
--image-ref "${IMAGE}:${{ steps.event.outputs.tag_full }}"
--image-ref "${DOCKERHUB_REGISTRY}/${IMAGE}:${{ steps.event.outputs.tag_full }}"
# echo "${DOCKERHUB_PASSWORD}" | sudo skopeo login --username "${DOCKERHUB_USERNAME}" --password-stdin index.docker.io
sudo skopeo copy "${IMAGE}:${{ steps.event.outputs.tag_full }}" "docker://${IMAGE}:${{ steps.event.outputs.tag_minor }}"
sudo skopeo copy "${IMAGE}:${{ steps.event.outputs.tag_full }}" "docker://${IMAGE}:${{ steps.event.outputs.tag_major }}"
sudo skopeo copy "${IMAGE}:${{ steps.event.outputs.tag_full }}" "docker://${IMAGE}:latest"
sudo skopeo copy "docker://${DOCKERHUB_REGISTRY}/${IMAGE}:${{ steps.event.outputs.tag_full }}" "docker://${DOCKERHUB_REGISTRY}/${IMAGE}:${{ steps.event.outputs.tag_minor }}"
sudo skopeo copy "docker://${DOCKERHUB_REGISTRY}/${IMAGE}:${{ steps.event.outputs.tag_full }}" "docker://${DOCKERHUB_REGISTRY}/${IMAGE}:${{ steps.event.outputs.tag_major }}"
sudo skopeo copy "docker://${DOCKERHUB_REGISTRY}/${IMAGE}:${{ steps.event.outputs.tag_full }}" "docker://${DOCKERHUB_REGISTRY}/${IMAGE}:latest"
echo "image=${IMAGE}" >> "$GITHUB_OUTPUT"
echo "digest=$(sudo skopeo inspect "${IMAGE}:${{ steps.event.outputs.tag_full }}" | jq -r .Digest)" >> "$GITHUB_OUTPUT"
- name: Docker login gcr.io
uses: docker/login-action@v3
env:
GCR_REGISTRY: "gcr.io"
GCR_USERNAME: "_json_key"
if: ${{ steps.parse_configs.outputs.push_to_gcr == 'true' }}
with:
username: ${{ env.GCR_USERNAME }}
password: ${{ secrets.GCR_PUSH_BOT_JSON_KEY }}
registry: ${{ env.GCR_REGISTRY }}
echo "digest=$(sudo skopeo inspect "docker://${DOCKERHUB_REGISTRY}/${IMAGE}:${{ steps.event.outputs.tag_full }}" | jq -r .Digest)" >> "$GITHUB_OUTPUT"
- name: Push to GCR
if: ${{ steps.parse_configs.outputs.push_to_gcr == 'true' }}
env:
GCR_PUSH_BOT_JSON_KEY: ${{ secrets.GCR_PUSH_BOT_JSON_KEY }}
run: |
echo "${GCR_PUSH_BOT_JSON_KEY}" | sudo skopeo login --username _json_key --password-stdin gcr.io
sudo skopeo copy "${{ steps.push.outputs.image }}" "docker://gcr.io/${{ github.repository }}:${{ steps.event.outputs.tag_full }}"
sudo skopeo copy "${{ steps.push.outputs.image }}" "docker://gcr.io/${{ github.repository }}:${{ steps.event.outputs.tag_minor }}"
sudo skopeo copy "${{ steps.push.outputs.image }}" "docker://gcr.io/${{ github.repository }}:${{ steps.event.outputs.tag_major }}"
sudo skopeo copy "${{ steps.push.outputs.image }}" "docker://gcr.io/${{ github.repository }}:latest"
echo "${GCR_PASSWORD}" | sudo skopeo login --username "${GCR_USERNAME}" --password-stdin "${GCR_REGISTRY}"
sudo skopeo copy "docker://${DOCKERHUB_REGISTRY}/${{ steps.push.outputs.image }}" "docker://${GCR_REGISTRY}/${{ github.repository }}:${{ steps.event.outputs.tag_full }}"
sudo skopeo copy "docker://${DOCKERHUB_REGISTRY}/${{ steps.push.outputs.image }}" "docker://${GCR_REGISTRY}/${{ github.repository }}:${{ steps.event.outputs.tag_minor }}"
sudo skopeo copy "docker://${DOCKERHUB_REGISTRY}/${{ steps.push.outputs.image }}" "docker://${GCR_REGISTRY}/${{ github.repository }}:${{ steps.event.outputs.tag_major }}"
sudo skopeo copy "docker://${DOCKERHUB_REGISTRY}/${{ steps.push.outputs.image }}" "docker://${GCR_REGISTRY}/${{ github.repository }}:latest"
- name: Register with CNB Registry
uses: docker://ghcr.io/buildpacks/actions/registry/request-add-entry:main
Expand Down

0 comments on commit a9bcbd9

Please sign in to comment.