This repository has been archived by the owner on May 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
134 lines (129 loc) · 5.86 KB
/
u24_workflow_release.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
name: u24_workflow_release
on:
workflow_call:
inputs:
jhub_ver:
required: true
type: string
py_ver:
required: true
type: string
dist:
required: true
type: string
secrets:
REGISTRY_USERNAME:
required: true
REGISTRY_PASSWORD:
required: true
jobs:
build_env_image:
runs-on: ubuntu-latest
env:
JHUB_VER: ${{inputs.jhub_ver}}
PY_VER: ${{inputs.py_ver}}
DIST: ${{inputs.dist}}
steps:
- name: Checkout workflow repo
uses: actions/checkout@v3
with:
path: 'main'
- name: Checkout cicd repo that has common docker template
uses: actions/checkout@v3
with:
## change to Prod owner
repository: 'dj-sciops/djsciops-cicd'
path: 'cicd'
- id: build_env
name: Build codebook env image
run: |
## Get docker template
cp -r ${GITHUB_WORKSPACE}/cicd/docker-template/u24_codebook_env ./main/docker/
echo "INFO :: Get build info"
cd ${GITHUB_WORKSPACE}/main
export PKG_NAME=$(ls | grep workflow)
export WORKFLOW_VERSION=$(cat ${PKG_NAME}/version.py | grep -oP '\d+\.\d+\.[a-z0-9]+')
cd ${GITHUB_WORKSPACE}/main/docker/u24_codebook_env
export REPO_NAME=$(echo ${{github.repository}} | awk -F\/ '{print $2}')
export REPO_OWNER=${{github.repository_owner}}
echo "INFO :: Build image"
docker-compose -f ${GITHUB_WORKSPACE}/main/docker/u24_codebook_env/dist/${DIST}/docker-compose-codebook_env.yaml build
echo "INFO :: Compress image"
cd ${GITHUB_WORKSPACE}
docker save \
-o image-codebook-${REPO_NAME}-jhub${JHUB_VER}-py${PY_VER}-${DIST}-${WORKFLOW_VERSION}.tar \
"datajoint/codebook_${REPO_NAME}:jhub${JHUB_VER}-py${PY_VER}-${DIST}-${WORKFLOW_VERSION}"
gzip -S ".gz" image-codebook-${REPO_NAME}-jhub${JHUB_VER}-py${PY_VER}-${DIST}-${WORKFLOW_VERSION}.tar
echo "repo_name=${REPO_NAME}" >> $GITHUB_ENV
echo "workflow_version=${WORKFLOW_VERSION}" >> $GITHUB_ENV
- name: Add codebook env image archive to Artifact
uses: actions/upload-artifact@v2
with:
name: "image-codebook-${{env.repo_name}}-jhub${{env.JHUB_VER}}-py${{env.PY_VER}}-${{env.DIST}}-${{env.workflow_version}}"
path: "image-codebook-${{env.repo_name}}-jhub${{env.JHUB_VER}}-py${{env.PY_VER}}-${{env.DIST}}-${{env.workflow_version}}.tar.gz"
retention-days: 90
outputs:
repo_name: ${{env.repo_name}}
workflow_version: ${{env.workflow_version}}
publish_env_image:
runs-on: ubuntu-latest
needs: build_env_image
env:
JHUB_VER: ${{inputs.jhub_ver}}
PY_VER: ${{inputs.py_ver}}
DIST: ${{inputs.dist}}
steps:
- name: Checkout workflow repo
uses: actions/checkout@v3
- name: Fetch image archive from Artifact
uses: actions/download-artifact@v2
with:
name: "image-codebook-${{needs.build_env_image.outputs.repo_name}}-jhub${{env.JHUB_VER}}-py${{env.PY_VER}}-${{env.DIST}}-${{needs.build_env_image.outputs.workflow_version}}"
- name: Get changelog entry
id: changelog_reader
uses: guzman-raphael/changelog-reader-action@v5
with:
path: ./CHANGELOG.md
- name: Create GH release
id: create_gh_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
with:
tag_name: ${{steps.changelog_reader.outputs.version}}
release_name: Release ${{steps.changelog_reader.outputs.version}}
body: ${{steps.changelog_reader.outputs.changes}}
prerelease: ${{steps.changelog_reader.outputs.status == 'prereleased'}}
draft: ${{steps.changelog_reader.outputs.status == 'unreleased'}}
- name: Upload image archive to Release
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
with:
upload_url: ${{steps.create_gh_release.outputs.upload_url}}
asset_path: "image-codebook-${{needs.build_env_image.outputs.repo_name}}-jhub${{env.JHUB_VER}}-py${{env.PY_VER}}-${{env.DIST}}-${{needs.build_env_image.outputs.workflow_version}}.tar.gz"
asset_name: "image-codebook-${{needs.build_env_image.outputs.repo_name}}-jhub${{env.JHUB_VER}}-py${{env.PY_VER}}-${{env.DIST}}-${{needs.build_env_image.outputs.workflow_version}}.tar.gz"
asset_content_type: application/gzip
- name: Load image archive to docker
run: |
## If your local machine is not the same as the "runs-on", this step would fail: invalid tar header
## If download image artifact from a different workflow, this step would fail: invalid tar header
docker load \
-i "image-codebook-${{needs.build_env_image.outputs.repo_name}}-jhub${{env.JHUB_VER}}-py${{env.PY_VER}}-${{env.DIST}}-${{needs.build_env_image.outputs.workflow_version}}.tar.gz"
- name: Login to vathes Registry
uses: docker/login-action@v1
with:
registry: docker.io
username: ${{ secrets.REGISTRY_USERNAME }}
password: ${{ secrets.REGISTRY_PASSWORD }}
- name: Push image
run: |
export IMAGE=datajoint/codebook_${{needs.build_env_image.outputs.repo_name}}
export TAG=jhub${{env.JHUB_VER}}-py${{env.PY_VER}}-${{env.DIST}}-${{needs.build_env_image.outputs.workflow_version}}
docker push "${IMAGE}:${TAG}"
docker tag "${IMAGE}:${TAG}" "${IMAGE}:${TAG}-${GITHUB_SHA:0:7}"
docker push "${IMAGE}:${TAG}-${GITHUB_SHA:0:7}"
[ "$PY_VER" == "3.8" ] && [ "$DISTRO" == "alpine" ] \
&& docker tag "${IMAGE}:${TAG}" "${IMAGE}:latest" \
&& docker push "${IMAGE}:latest" \
|| echo "skipping 'latest' tag..."