-
Notifications
You must be signed in to change notification settings - Fork 10
47 lines (43 loc) · 1.89 KB
/
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
name: Docker Build
on: [push, pull_request]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Prepare
id: prepare
run: |
IMAGE_NAME=modelsaber
DOCKER_USER=`echo ${{ github.repository }} | cut -d "/" -f 1 | tr '[:upper:]' '[:lower:]'`
DOCKER_REPO=`echo "${{ github.repository }}" | tr '[:upper:]' '[:lower:]'`
DOCKER_IMAGE=docker.pkg.github.com/$DOCKER_REPO/$IMAGE_NAME
VERSION=`git rev-parse --short HEAD`
if [[ $GITHUB_REF == refs/tags/* ]]; then
VERSION=${GITHUB_REF#refs/tags/v}
fi
echo ::set-output name=docker_user::${DOCKER_USER}
echo ::set-output name=docker_image::${DOCKER_IMAGE}
echo ::set-output name=version::${VERSION}
- name: Setup Docker Buildx
uses: crazy-max/ghaction-docker-buildx@v3
- name: Cache Docker layers
uses: actions/cache@v2
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Build Docker Image
run: |
docker buildx build \
--cache-from "type=local,src=/tmp/.buildx-cache" \
--cache-to "type=local,dest=/tmp/.buildx-cache" \
--output "type=docker" \
--tag ${{ steps.prepare.outputs.docker_image }}:${{ steps.prepare.outputs.version }} \
--file Dockerfile .
- name: Login to Docker Registry
run: echo ${{ secrets.GITHUB_TOKEN }} | docker login docker.pkg.github.com --username ${{ steps.prepare.outputs.docker_user }} --password-stdin
- name: Push to Docker Registry
if: (github.ref == 'refs/heads/master') || (contains(github.ref, 'refs/tags/') == true)
run: docker push ${{ steps.prepare.outputs.docker_image }}:${{ steps.prepare.outputs.version }}