Skip to content

Commit

Permalink
Changed: improvements towards a functional docker push job
Browse files Browse the repository at this point in the history
What does this change do ?

- Changed: improvements towards a functional docker push job
- Fixes broken azure pipeline

Why is this change needed ?

- To ensure docker push works as required
  • Loading branch information
stephenmoloney committed Dec 25, 2020
1 parent 006f3e3 commit 0607f20
Show file tree
Hide file tree
Showing 10 changed files with 305 additions and 51 deletions.
14 changes: 5 additions & 9 deletions .azure-pipelines/templates/02_docker_build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@ stages:
)
dependsOn: []
jobs:
- job: build
- job: build_saleor_core
displayName: Build saleor-core image
condition: always()
depends_on: []
steps:
- template: ../init_step.yaml

Expand All @@ -27,10 +26,9 @@ stages:
script: |
make build_saleor_core
- job: build
- job: build_saleor_core_dev
displayName: Build saleor-core-dev image
condition: always()
depends_on: []
steps:
- template: ../init_step.yaml

Expand All @@ -45,10 +43,9 @@ stages:
script: |
make build_saleor_core_dev
- job: build
- job: build_saleor_dashboard
displayName: Build saleor-dashboard image
condition: always()
depends_on: []
steps:
- template: ../init_step.yaml

Expand All @@ -63,10 +60,9 @@ stages:
script: |
make build_saleor_dashboard
- job: build
displayName: Build saleor-storefront
- job: build_saleor_storefront
displayName: Build saleor-storefront image
condition: always()
depends_on: []
steps:
- template: ../init_step.yaml

Expand Down
91 changes: 91 additions & 0 deletions .azure-pipelines/templates/03_docker_push.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# @format
---
stages:
- stage: Push
displayName: Push images
condition: eq(variables['Build.SourceBranch'], 'refs/heads/master')
dependsOn: []
jobs:
- job: push_saleor_core
displayName: Push saleor-core image
condition: always()
steps:
- template: ../init_step.yaml

- task: Bash@3
displayName: Push saleor-core image
inputs:
targetType: "inline"
workingDirectory: "$(Build.Repository.LocalPath)"
failOnStderr: false
noProfile: true
noRc: true
script: |
make build_saleor_core
make push_saleor_core
env:
REGISTRY_TOKEN: $(registryToken)
FORCE_PUSH_IMAGES: $(forcePush)

- job: push_saleor_core_dev
displayName: Push saleor-core-dev image
condition: always()
steps:
- template: ../init_step.yaml

- task: Bash@3
displayName: Push saleor-core-dev image
inputs:
targetType: "inline"
workingDirectory: "$(Build.Repository.LocalPath)"
failOnStderr: false
noProfile: true
noRc: true
script: |
make build_saleor_core_dev
make push_saleor_core_dev
env:
REGISTRY_TOKEN: $(registryToken)
FORCE_PUSH_IMAGES: $(forcePush)

- job: push_saleor_dashboard
displayName: Push saleor-dashboard image
condition: always()
steps:
- template: ../init_step.yaml

- task: Bash@3
displayName: Push saleor-dashboard image
inputs:
targetType: "inline"
workingDirectory: "$(Build.Repository.LocalPath)"
failOnStderr: false
noProfile: true
noRc: true
script: |
make build_saleor_dashboard
make push_saleor_dashboard
env:
REGISTRY_TOKEN: $(registryToken)
FORCE_PUSH_IMAGES: $(forcePush)

- job: push_saleor_storefront
displayName: Push saleor-storefront image
condition: always()
steps:
- template: ../init_step.yaml

- task: Bash@3
displayName: Push saleor-storefront image
inputs:
targetType: "inline"
workingDirectory: "$(Build.Repository.LocalPath)"
failOnStderr: false
noProfile: true
noRc: true
script: |
make build_saleor_storefront
make push_saleor_storefront
env:
REGISTRY_TOKEN: $(registryToken)
FORCE_PUSH_IMAGES: $(forcePush)
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
node_modules
.env
saleor_core
saleor_core_dev
saleor_dashboard
saleor_storefront
charts/saleor-platform/charts
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

**_Added_**

- Saleor source code built as docker images rebuilt with customizations required for the k8s deployments
- Saleor source code built as docker images rebuilt with customizations required for the k8s deployments.
- Added initial helm charts with each component in it's own chart, namely:
- saleor-core
- saleor-storefront
- saleor-dashboard
- Added an umbrella chart with all chart dependencies (sub-charts) specified for consumption.
- Added scripts and makefile for CI operations
- Added scripts and makefile for CI operations.
162 changes: 135 additions & 27 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,19 @@ SHELL := /bin/bash
init_all \
format_all \
lint_all \
prepare_saleor_sources \
build_saleor_core \
build_saleor_core_dev \
build_saleor_dashboard \
build_saleor_storefront \
push_saleor_core \
push_saleor_core_dev \
push_saleor_dashboard \
push_saleor_storefront \
get_image \
get_image_version


## Dependency installation targets

init_yarn:
Expand Down Expand Up @@ -70,15 +78,53 @@ lint_all: init_all
./scripts/make.sh lint_dockerfiles

get_image:
@./scripts/make.sh get_image saleor_core
@if test -z "$(FILTER)"; then \
echo "env variable FILTER is required" && \
exit 1; \
fi;
@./scripts/make.sh get_image "${FILTER}"
unset FILTER

get_image_version:
@./scripts/make.sh get_image_version

build_saleor_core:
@if test -z "$(SALEOR_REPO)"; then \
echo "env variable SALEOR_REPO is required" && \
exit 1; \
fi;
@./scripts/make.sh get_image_version "${SALEOR_REPO}"
unset SALEOR_REPO

push_image:
@if test -z "$(IMAGE_VERSION)"; then \
echo "env variable IMAGE_VERSION is required" && \
exit 1; \
fi;
@if test -z "$(DOCKER_REPO)"; then \
echo "env variable DOCKER_REPO is required" && \
exit 1; \
fi;
@./scripts/make.sh push_image "${IMAGE_VERSION}" "${DOCKER_REPO}" "${FORCE_PUSH}"
unset IMAGE_VERSION
unset DOCKER_REPO

prepare_saleor_sources:
./scripts/make.sh prepare_saleor_source \
"https://github.com/mirumee/saleor.git" \
"Core.Dockerfile" && \
./scripts/make.sh prepare_saleor_source \
"https://github.com/mirumee/saleor.git" \
"Core.Dev.Dockerfile" && \
./scripts/make.sh prepare_saleor_source \
"https://github.com/mirumee/saleor-dashboard.git" \
"Dashboard.Dockerfile" && \
./scripts/make.sh prepare_saleor_source \
"https://github.com/mirumee/saleor-storefront.git" \
"Storefront.Dockerfile"

build_saleor_core: prepare_saleor_sources
./scripts/make.sh set_env_saleor_core
./scripts/make.sh prepare_saleor_source "https://github.com/mirumee/saleor.git" "Core.Dockerfile"
docker-compose build saleor_core
docker image ls
make -s get_image FILTER=saleor_core
docker run \
--rm "$$(make -s get_image FILTER=saleor_core)" \
/bin/bash -c 'echo "build ok"' || \
Expand All @@ -87,10 +133,11 @@ build_saleor_core:
"$$(make -s get_image FILTER=saleor_core)"
rm .env

build_saleor_core_dev:
build_saleor_core_dev: prepare_saleor_sources
./scripts/make.sh set_env_saleor_core_dev
./scripts/make.sh prepare_saleor_source "https://github.com/mirumee/saleor.git" "Core.Dev.Dockerfile"
docker-compose build saleor_core_dev
docker image ls
make -s get_image FILTER=saleor_core_dev
docker run \
--rm "$$(make -s get_image FILTER=saleor_core_dev)" \
/bin/bash -c 'echo "build ok"' || \
Expand All @@ -99,10 +146,11 @@ build_saleor_core_dev:
"$$(make -s get_image FILTER=saleor_core_dev)"
rm .env

build_saleor_dashboard:
build_saleor_dashboard: prepare_saleor_sources
./scripts/make.sh set_env_saleor_dashboard
./scripts/make.sh prepare_saleor_source "https://github.com/mirumee/saleor-dashboard.git" "Dashboard.Dockerfile"
docker-compose build saleor_dashboard
docker image ls
make -s get_image FILTER=saleor_dashboard
docker run \
--rm "$$(make -s get_image FILTER=saleor_dashboard)" \
/bin/bash -c 'echo "build ok"' || \
Expand All @@ -111,10 +159,11 @@ build_saleor_dashboard:
"$$(make -s get_image FILTER=saleor_dashboard)"
rm .env

build_saleor_storefront:
build_saleor_storefront: prepare_saleor_sources
./scripts/make.sh set_env_saleor_storefront
./scripts/make.sh prepare_saleor_source "https://github.com/mirumee/saleor-storefront.git" "Dashboard.Dockerfile"
docker-compose build saleor_storefront
docker image ls
make -s get_image FILTER=saleor_storefront
docker run \
--rm "$$(make -s get_image FILTER=saleor_storefront)" \
/bin/bash -c 'echo "build ok"' || \
Expand All @@ -123,19 +172,78 @@ build_saleor_storefront:
"$$(make -s get_image FILTER=saleor_storefront)"
rm .env

#push_saleor_core:
# @if test -z "$(REGISTRY_TOKEN)"; then \
# echo "env variable REGISTRY_TOKEN is required" && \
# exit 1; \
# fi;
# docker tag \
# "$$(make -s get_image FILTER=saleor_core)" \
# "ghcr.io/eirenauts/saleor-core:$$(make -s get_image_version)"
# docker tag \
# "$$(make -s get_image FILTER=saleor_core)" \
# "ghcr.io/eirenauts/saleor-core:latest"
# echo "${REGISTRY_TOKEN}" | docker login ghcr.io -u eirenauts --password-stdin
# docker push "ghcr.io/eirenauts/saleor-core:$$(make -s get_image_version)"
# docker push "ghcr.io/eirenauts/saleor-core:latest"
# docker logout ghcr.io
# if [[ -e /home/vsts/.docker/config.json ]]; then rm /home/vsts/.docker/config.json; fi
push_saleor_core:
@if test -z "$(REGISTRY_TOKEN)"; then \
echo "env variable REGISTRY_TOKEN is required" && \
exit 1; \
fi;
docker tag \
"$$(make -s get_image FILTER=saleor_core)" \
"ghcr.io/eirenauts/saleor-core:$$(make -s get_image_version SALEOR_REPO=https://github.com/mirumee/saleor.git)"
docker tag \
"$$(make -s get_image FILTER=saleor_core)" \
"ghcr.io/eirenauts/saleor-core:latest"
echo "${REGISTRY_TOKEN}" | docker login ghcr.io -u eirenauts --password-stdin
make -s push_image \
IMAGE_VERSION="$$(make -s get_image_version SALEOR_REPO=https://github.com/mirumee/saleor.git)" \
DOCKER_REPO=saleor-core \
FORCE_PUSH="${FORCE_PUSH_IMAGES}"
docker logout ghcr.io
if [[ -e /home/vsts/.docker/config.json ]]; then rm /home/vsts/.docker/config.json; fi

push_saleor_core_dev:
@if test -z "$(REGISTRY_TOKEN)"; then \
echo "env variable REGISTRY_TOKEN is required" && \
exit 1; \
fi;
docker tag \
"$$(make -s get_image FILTER=saleor_core_dev)" \
"ghcr.io/eirenauts/saleor-core:dev-$$(make -s get_image_version SALEOR_REPO=https://github.com/mirumee/saleor.git)"
docker tag \
"$$(make -s get_image FILTER=saleor_core_dev)" \
"ghcr.io/eirenauts/saleor-core:dev-latest"
echo "${REGISTRY_TOKEN}" | docker login ghcr.io -u eirenauts --password-stdin
make -s push_image \
IMAGE_VERSION="$$(make -s get_image_version SALEOR_REPO=https://github.com/mirumee/saleor.git)" \
DOCKER_REPO=saleor-core \
FORCE_PUSH="${FORCE_PUSH_IMAGES}"
docker logout ghcr.io
if [[ -e /home/vsts/.docker/config.json ]]; then rm /home/vsts/.docker/config.json; fi

push_saleor_dashboard:
@if test -z "$(REGISTRY_TOKEN)"; then \
echo "env variable REGISTRY_TOKEN is required" && \
exit 1; \
fi;
docker tag \
"$$(make -s get_image FILTER=saleor_dashboard)" \
"ghcr.io/eirenauts/saleor-dashboard:$$(make -s get_image_version SALEOR_REPO=https://github.com/mirumee/saleor-dashboard.git)"
docker tag \
"$$(make -s get_image FILTER=saleor_dashboard)" \
"ghcr.io/eirenauts/saleor-dashboard:latest"
echo "${REGISTRY_TOKEN}" | docker login ghcr.io -u eirenauts --password-stdin
make -s push_image \
IMAGE_VERSION="$$(make -s get_image_version SALEOR_REPO=https://github.com/mirumee/saleor-dashboard.git)" \
DOCKER_REPO=saleor-dashboard \
FORCE_PUSH="${FORCE_PUSH_IMAGES}"
docker logout ghcr.io
if [[ -e /home/vsts/.docker/config.json ]]; then rm /home/vsts/.docker/config.json; fi

push_saleor_storefront:
@if test -z "$(REGISTRY_TOKEN)"; then \
echo "env variable REGISTRY_TOKEN is required" && \
exit 1; \
fi;
docker tag \
"$$(make -s get_image FILTER=saleor_storefront)" \
"ghcr.io/eirenauts/saleor-storefront:$$(make -s get_image_version SALEOR_REPO=https://github.com/mirumee/saleor-storefront.git)"
docker tag \
"$$(make -s get_image FILTER=saleor_storefront)" \
"ghcr.io/eirenauts/saleor-storefront:latest"
echo "${REGISTRY_TOKEN}" | docker login ghcr.io -u eirenauts --password-stdin
make -s push_image \
IMAGE_VERSION="$$(make -s get_image_version SALEOR_REPO=https://github.com/mirumee/saleor-storefront.git)" \
DOCKER_REPO=saleor-storefront \
FORCE_PUSH="${FORCE_PUSH_IMAGES}"
docker logout ghcr.io
if [[ -e /home/vsts/.docker/config.json ]]; then rm /home/vsts/.docker/config.json; fi
8 changes: 4 additions & 4 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@ services:
UID: 1001
GUID: 1001

saleor_core_dashboard:
saleor_dashboard:
build:
context: ./saleor_core_dashboard
context: ./saleor_dashboard
dockerfile: Dockerfile
args:
SHORT_SHA: ${SHORT_SHA}
VERSION: ${VERSION}

saleor_core_storefront:
saleor_storefront:
build:
context: ./saleor_core_storefront
context: ./saleor_storefront
dockerfile: Dockerfile
args:
SHORT_SHA: ${SHORT_SHA}
Expand Down
Loading

0 comments on commit 0607f20

Please sign in to comment.