-
Notifications
You must be signed in to change notification settings - Fork 0
75 lines (72 loc) · 2.59 KB
/
docker.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
name: Push latest release to DockerHub
on:
push:
branches: [master]
paths-ignore:
- "README.md"
env:
DOCKER_USERNAME: unfor19
DOCKER_ORG: unfor19
DOCKER_REPO: alpine-ci
DOCKER_VERSION_FILE_PATH: /opt/alpineci_version
jobs:
dockerhub-latest:
runs-on: ubuntu-20.04
strategy:
matrix:
include:
- DOCKERFILE_PATH: Dockerfile
DOCKER_BUILD_TARGET: alpine-ci
DOCKER_TAG_ONLY: latest
- DOCKERFILE_PATH: Dockerfile
DOCKER_BUILD_TARGET: awscli
DOCKER_TAG_ONLY: awscli-latest
- DOCKERFILE_PATH: Dockerfile
DOCKER_BUILD_TARGET: awscli-docker
DOCKER_TAG_ONLY: awscli-docker-latest
- DOCKERFILE_PATH: Dockerfile
DOCKER_BUILD_TARGET: docker-python
DOCKER_TAG_ONLY: awscli-docker-python-latest
steps:
- uses: actions/checkout@v2
- name: Inject slug/short variables
uses: rlespinasse/github-slug-action@v3.x
- uses: docker/setup-buildx-action@v1
id: buildx
with:
install: true
- name: Inject env vars
run: |
export DOCKER_TAG_LATEST=${DOCKER_ORG}/${DOCKER_REPO}:${{ matrix.DOCKER_TAG_ONLY }}
export DOCKER_TAG_RELEASE=${DOCKER_ORG}/${DOCKER_REPO}:${{ matrix.DOCKER_TAG_ONLY }}-${GITHUB_SHA:0:8}
echo "DOCKER_TAG_LATEST=${DOCKER_TAG_LATEST}" >> version
echo "DOCKER_TAG_RELEASE=${DOCKER_TAG_RELEASE}" >> version
cat version >> "$GITHUB_ENV"
- name: Cache Docker layers
uses: actions/cache@v2
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-docker-${{ github.sha }}
restore-keys: |
${{ runner.os }}-docker
- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ env.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Push to DockerHub
run: |
docker buildx build \
$(cat version | sed 's~^~--build-arg ~g' | tr '\n' ' ' ) \
--cache-from "type=local,src=/tmp/.buildx-cache" \
--cache-to "type=local,dest=/tmp/.buildx-cache-new" \
--output "type=image,push=true" \
--tag "$DOCKER_TAG_RELEASE" \
--tag "$DOCKER_TAG_LATEST" \
--target "${{ matrix.DOCKER_BUILD_TARGET }}" \
--file ./Dockerfile .
echo -e "\nPushed:\n${DOCKER_TAG_LATEST}\n${DOCKER_TAG_RELEASE}"
- name: Move cache
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache