generated from berkeley-dsep-infra/hub-user-image-template
-
Notifications
You must be signed in to change notification settings - Fork 3
117 lines (104 loc) · 4.02 KB
/
build-push-image-commit.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
name: Build and push container image, and push update to datahub repo if needed
on:
push:
branches:
- main
jobs:
build-and-push:
runs-on: ubuntu-latest
env:
DOCKER_CONFIG: $HOME/.docker
IMAGE: ${{ vars.IMAGE }}
outputs:
image-tag: ${{ steps.build-and-push.outputs.IMAGE_SHA_TAG }}
steps:
- name: Cleanup disk space
run: |
sudo rm -rf /usr/local/lib/android /usr/share/dotnet /opt/ghc
df -h
- name: Check out the image repo
uses: actions/checkout@v4
with:
fetch-depth: 0 # OR "2" -> To retrieve the preceding commit.
- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@v44
with:
files_ignore: |
README.md
CONTRIBUTING.md
LICENSE
.github/**
images/**
- name: Log in to GAR
if: steps.changed-files.outputs.any_changed == 'true'
uses: docker/login-action@v3
with:
registry: us-central1-docker.pkg.dev
username: _json_key
password: ${{ secrets.GAR_SECRET_KEY }}
- name: Build the image and push to artifact registry
id: build-and-push
if: steps.changed-files.outputs.any_changed == 'true'
uses: jupyterhub/repo2docker-action@master
with:
DOCKER_REGISTRY: us-central1-docker.pkg.dev
IMAGE_NAME: ${{ env.IMAGE }}
# Disable pushing a 'latest' tag, as this often just causes confusion
LATEST_TAG_OFF: true
# Put repo contents in /srv/repo, rather than the default (/home/jovyan). The home directory
# is mounted over by persistent storage when we are using the built image in a JupyterHub, and
# so all contents put in /home/jovyan are lost. This particularly prevents any 'start' script from
# working, as it is needed in runtime.
REPO_DIR: /srv/repo
# Lets us monitor disks getting full as images get bigger over time
- name: Show how much disk space is left
run: df -h
update-deployment-image-tag:
runs-on: ubuntu-latest
needs: build-and-push
env:
HUB: ${{ vars.HUB }}
IMAGE: ${{ vars.IMAGE }}
IMAGE_TAG: ${{ needs.build-and-push.outputs.image-tag }}
steps:
- name: Checkout the datahub repo
if: ${{ env.IMAGE_TAG }}
uses: actions/checkout@v4
with:
token: ${{ secrets.DATAHUB_CREATE_PR }}
fetch-depth: 0
repository: 'berkeley-dsep-infra/datahub'
sparse-checkout: |
deployments/
hub/
- name: Set git identity
if: ${{ env.IMAGE_TAG }}
run: |
git config --global user.email "${{ vars.IMAGE_BUILDER_BOT_EMAIL }}"
git config --global user.name "${{ vars.IMAGE_BUILDER_BOT_NAME }}"
- name: Update the tag for any deployments that use this image
if: ${{ env.IMAGE_TAG }}
run: |
for deployment in $(grep -lr ${IMAGE} deployments/ | grep hubploy.yaml); do
old_hash=$(grep ${IMAGE} ${deployment} | awk -F":" '{print $3}')
new_hash=${IMAGE_TAG}
sed -i -e "s/${old_hash}/${new_hash}/g" ${deployment}
echo "Updated ${deployment} with new image tag ${new_hash}"
done
- name: Create feature branch, add, commit and push changes
if: ${{ env.IMAGE_TAG }}
run: |
CHANGED_FILES=$(git status --porcelain -uno | awk '{print $2}')
git diff
git checkout -b update-${HUB}-image-tag-${IMAGE_TAG}
# to be safe, only add files that have changed
for file in $(echo -e ${CHANGED_FILES}); do
git add ${file}
done
git commit -m "update ${HUB} image tag to ${IMAGE_TAG}: ${CHANGED_FILES}"
git push origin update-${HUB}-image-tag-${IMAGE_TAG}
- name: Print out a message if no PR is created
if: ${{ ! env.IMAGE_TAG }}
run: |
echo "Image not updated, no push to datahub repo required"