-
Notifications
You must be signed in to change notification settings - Fork 27
78 lines (75 loc) · 3.23 KB
/
deploy_docker.yml
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
# GitHub workflow for deploying the Docker image to Docker Hub.
# This is done by substituting and compiling the code
# from the master branch into the concept:test-build image,
# then pushing it as concept:latest.
name: deploy_docker
on:
push:
branches:
- master
jobs:
check_deploy:
runs-on: ubuntu-22.04
outputs:
deploy: ${{ steps.check_deploy.outputs.deploy }}
steps:
- name: 📝 Check whether to deploy
id: check_deploy
env:
docker_password: ${{ secrets.DOCKER_PASSWORD }}
run: |
if [ -n "${docker_password}" ]; then
echo "Will be deployed"
echo "deploy=1" >> "${GITHUB_OUTPUT}"
else
echo "Will not be deployed"
fi
deploy_docker:
runs-on: ubuntu-22.04
needs: check_deploy
if: needs.check_deploy.outputs.deploy
steps:
- name: 🛎️ Checkout
uses: actions/checkout@v4
- name: 🐋 Clean dangling Docker containers
uses: ./.github/actions/docker-clean
- name: 📝 Set temporary Docker container name
run: |
echo "docker_container=${GITHUB_REPOSITORY//\//_}__${GITHUB_WORKFLOW}__${GITHUB_JOB}__$(date +%s)" >> "${GITHUB_ENV}"
- name: 🐋 Pull Docker image
run: docker pull ${{ secrets.DOCKER_USERNAME }}/concept:test-build
- name: 🔧 Build code
run: |
docker run \
-v "${GITHUB_WORKSPACE}":/github \
--name ${docker_container} \
${{ secrets.DOCKER_USERNAME }}/concept:test-build \
bash -O extglob -c ': \
&& source ~/.bashrc \
&& rm -rf "${concept_dir}/"!(dep) \
&& cp -r /github/!(dep) "${concept_dir}/" \
&& (cd "${concept_dir}" && make distclean) \
&& make_jobs="-j 1" concept \
&& (cd "${concept_dir}" && make clean-job) \
&& mkdir -p "${tmp_dir}/so" \
&& mv "${build_dir}"/*.so "${tmp_dir}/so/" \
&& (cd "${concept_dir}" && make clean) \
&& mkdir -p "${build_dir}" \
&& mv "${tmp_dir}"/so/* "${build_dir}/" \
&& (cd "${concept_dir}" && make clean-tmp) \
&& (find / -type d -a -name "__pycache__" -exec rm -rf "{}" + || :) \
'
docker commit \
--change='CMD ["bash"]' \
${docker_container} \
${{ secrets.DOCKER_USERNAME }}/concept:latest
docker rm -f ${docker_container} 2>/dev/null || :
- name: 🚀 Deploy Docker image
run: |
echo ${{ secrets.DOCKER_PASSWORD }} \
| docker login \
-u ${{ secrets.DOCKER_USERNAME }} \
--password-stdin \
2>/dev/null
docker push ${{ secrets.DOCKER_USERNAME }}/concept:latest
docker logout