-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.yml
123 lines (123 loc) · 3.82 KB
/
action.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
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
name: Spack step
description: 'Builds a step of docker image'
inputs:
GITHUB_TOKEN:
required: true
description: "GITHUB_TOKEN"
path:
required: true
description: "path to the Dockerfile"
context:
default: '{{defaultContext}}:'
description: "Docker context"
image-name:
required: true
description: "Base name of the image to publish"
build-args:
default: ""
description: "Arguments to pass to the build"
cache:
default: true
description: "Whether to use cache"
tags:
default: ""
description: "Additional tags"
swap:
default: "0"
description: "Additional swap to allocate"
test:
default: false
description: "Whether to build the test target before publishing"
target:
default:
description: "Target to build"
runs:
using: "composite"
steps:
- id: setup
shell: bash
run: |
set -ex
echo " === additional tags: ==="
cat<<'EOF'
${{ inputs.tags }}
EOF
echo " === ==="
if [ -f docker_image_step_SETUP_ALREADY_DONE ]
then echo "done=true" >> "${GITHUB_OUTPUT}"
else
echo "done=false" >> "${GITHUB_OUTPUT}"
docker system prune -af --volumes
sudo systemctl stop docker.socket
sudo systemctl stop docker.service
sudo mv /var/lib/docker /mnt
sudo mkdir /var/lib/docker
sudo mount -o bind /mnt/docker /var/lib/docker
sudo systemctl start docker.service
sudo systemctl start docker.socket
fi
touch docker_image_step_SETUP_ALREADY_DONE
- if: "${{ steps.setup.outputs.done != 'true' }}"
uses: docker/login-action@v3
with: { registry: "ghcr.io", username: "${{ github.actor }}", password: "${{ inputs.GITHUB_TOKEN }}" }
- if: "${{ steps.setup.outputs.done != 'true' }}"
uses: docker/setup-buildx-action@v3
- id: info
shell: bash
run: |
if [ 'true' = '${{ contains(inputs.image-name,':') }}' ]
then echo "sep=-" >> "${GITHUB_OUTPUT}"
else echo "sep=:" >> "${GITHUB_OUTPUT}"
fi
echo "sha=${GITHUB_SHA:0:7}" >> "${GITHUB_OUTPUT}"
- if: "${{ inputs.test == 'true' }}"
uses: docker/build-push-action@v5
with:
cache-from: "ghcr.io/pdidev/test_env/cache/${{ inputs.image-name }}"
build-args: |
${{ inputs.build-args }}
IMAGE_TAG=${{ steps.info.outputs.sha }}
context: "${{ inputs.context }}${{ inputs.path }}"
load: true
target: test
- if: "${{ inputs.swap != '0' }}"
shell: bash
run: |
sudo fallocate -l "${{ inputs.swap }}" /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
- if: "${{ inputs.cache == 'true' }}"
uses: docker/build-push-action@v5
with:
cache-from: "ghcr.io/pdidev/test_env/cache/${{ inputs.image-name }}"
cache-to: "ghcr.io/pdidev/test_env/cache/${{ inputs.image-name }}"
build-args: |
${{ inputs.build-args }}
IMAGE_TAG=${{ steps.info.outputs.sha }}
tags: |
ghcr.io/pdidev/test_env/${{ inputs.image-name }}${{ steps.info.outputs.sep }}${{ steps.info.outputs.sha }}
${{ inputs.tags }}
context: "${{ inputs.context }}${{ inputs.path }}"
push: true
target: ${{ inputs.target }}
- if: "${{ inputs.cache != 'true' }}"
uses: docker/build-push-action@v5
with:
build-args: |
${{ inputs.build-args }}
IMAGE_TAG=${{ steps.info.outputs.sha }}
tags: |
ghcr.io/pdidev/test_env/${{ inputs.image-name }}${{ steps.info.outputs.sep }}${{ steps.info.outputs.sha }}
${{ inputs.tags }}
context: "${{ inputs.context }}${{ inputs.path }}"
push: true
target: ${{ inputs.target }}
- name: "Remove swap file"
shell: bash
run: |
if [ -e /swapfile ]
then
sudo swapoff /swapfile || true
sudo rm -f /swapfile || true
fi