Skip to content

Commit

Permalink
Push docker image to Nexus Repository in CICD Workflow (#41)
Browse files Browse the repository at this point in the history
* nexus push 1

* nexus push 2

* nexus push 3

* nexus push 4

* nexus push 5

* nexus push 6

* nexus push date

* nexus push date 2

* nexus push merge test

* nexus push branch

* nexus push branch

* test branch name

* nexus push env variable test

* nexus push env variable test

* nexus push env varaible test

* nexus push env varaible test

* nexus push pull request test

* nexus push clean

* nexus push pull request

* better conditions for pushing on nexus

* add version to tag

* removes test "merge==true"

* corrects the images tags
  • Loading branch information
MichelDaab authored Sep 29, 2022
1 parent 007644c commit 8a731ad
Showing 1 changed file with 35 additions and 21 deletions.
56 changes: 35 additions & 21 deletions .github/workflows/cicd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ on:
branches:
- prod
- main
env:
nexus_server: 10.128.81.69:8082

jobs:
CICD:
Expand Down Expand Up @@ -60,30 +62,42 @@ jobs:
# Everything ran so we tag the valid docker image to keep it
# This happens for push events, which are in particular
# triggered when a pull request is merged.
- name: Get the branch name into an environment variable.
if: github.event_name == 'push'
uses: nelonoel/[email protected]

- name: Print the branch name
if: github.event_name == 'push'
run: echo ${BRANCH_NAME}

- name: Tag the docker image with branch name
if: github.event_name == 'push'
run: docker tag myria3d:latest myria3d:${BRANCH_NAME}

- name: Run the new, tagged image at least once so that is it not prunned by mistake when using docker system prune
if: github.event_name == 'push'
run: docker run myria3d:${BRANCH_NAME} bash

# This needs writing rights to the mounted path
- name: Save the docker image as myria3d_${BRANCH_NAME}.tar
if: github.event_name == 'push'
run: docker save myria3d:${BRANCH_NAME} -o /var/data/cicd/CICD_github_assets/CICD_docker_images/myria3d_${BRANCH_NAME}.tar
run: |
docker tag myria3d:latest myria3d:${{github.ref_name}}
docker run myria3d:${{github.ref_name}} bash # Run the new, tagged image at least once so that is it not prunned by mistake when using docker system prune
# docker save myria3d:${{github.ref_name}} -o /var/data/cicd/CICD_github_assets/CICD_docker_images/myria3d_${github.ref_name}.tar # Save the docker image as myria3d_${github.ref_name}.tar
# get version number and date, to tag the image pushed to nexus
- name: get version number
id: tag
run: |
echo "::set-output name=version::$(docker run myria3d grep '__version__' package_metadata.yaml| cut -d\" -f2)"
echo "::set-output name=date::$(date '+%Y.%m.%d')"
# show possible tags, for debugging purpose
- name: Print tags
run: |
echo "${{steps.tag.outputs.version}}"
echo "${{steps.tag.outputs.date}}"
- name: push main docker on nexus (tagged with a date)
# we push on nexus an image from the main branch when it has been updated (push or accepted pull request)
if: ((github.ref_name == 'main') && (github.event_name == 'push'))
run: |
docker tag myria3d $nexus_server/lidar_hd/myria3d:${{steps.tag.outputs.version}}-${{steps.tag.outputs.date}}
docker login $nexus_server --username svc_lidarhd --password ${{ secrets.PASSWORD_SVC_LIDARHD }}
docker push $nexus_server/lidar_hd/myria3d:${{steps.tag.outputs.version}}-${{steps.tag.outputs.date}}
- name: push branch docker on nexus (tagged with the branch name)
# we push on nexus an image from a branch when it's pushed
if: ((github.event_name == 'push') && (github.ref_name != 'main'))
run: |
docker tag myria3d $nexus_server/lidar_hd/myria3d:${{steps.tag.outputs.version}}-${{github.ref_name}}
docker login $nexus_server --username svc_lidarhd --password ${{ secrets.PASSWORD_SVC_LIDARHD }}
docker push $nexus_server/lidar_hd/myria3d:${{steps.tag.outputs.version}}-${{github.ref_name}}
- name: Clean dangling docker images
if: always() # always do it, even if something failed
run: docker system prune --force # remove dangling docker images, without asking user for confirmation



0 comments on commit 8a731ad

Please sign in to comment.