-
Notifications
You must be signed in to change notification settings - Fork 37
64 lines (51 loc) · 1.97 KB
/
build.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
name: Build Docker Image
on:
push:
branches:
- main
pull_request:
jobs:
build:
runs-on: ubuntu-20.04
env:
CI_DOCKER_IMAGE: orly
CI_DOCKERFILE: Dockerfile
CI_DOCKER_CONTEXT: .
CI_EXTERNAL_NAME: kirinnee/orly
steps:
- name: Check out Code
uses: actions/checkout@v2
- name: Log into GitHub registry
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login docker.pkg.github.com -u ${{ github.actor }} --password-stdin
- name: Generate image reference
run: |
IMAGE_ID=docker.pkg.github.com/${{ github.repository }}/$CI_DOCKER_IMAGE
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
# Strip git ref prefix from version
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
# Strip "v" prefix from tag name
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
# Use Docker `latest` tag convention
[ "$VERSION" == "main" ] && VERSION=latest
echo IMAGE_ID=$IMAGE_ID
echo VERSION=$VERSION
echo "IMAGE_ID=$IMAGE_ID" >> $GITHUB_ENV
echo "VERSION=$VERSION" >> $GITHUB_ENV
- name: Cache Pull
run: |
docker pull $IMAGE_ID || true
- name: Build image
run: docker build $CI_DOCKER_CONTEXT -f $CI_DOCKERFILE --tag $CI_DOCKER_IMAGE --cache-from=$IMAGE_ID
- name: Push image
run: |
IMAGE_REF=${{ env.IMAGE_ID }}:${{ env.VERSION }}
echo Docker Image reference: $IMAGE_REF
docker tag $CI_DOCKER_IMAGE $IMAGE_REF
docker push $IMAGE_REF
- name: Log into DockerHub registry
run: echo "${{ secrets.DOCKER_TOKEN }}" | docker login -u ${{ secrets.DOCKER_USER }} --password-stdin
- name: Push to DockerHub
run: |
DOCKERHUB_NAME=$CI_EXTERNAL_NAME:latest
docker tag $CI_DOCKER_IMAGE $DOCKERHUB_NAME
docker push $DOCKERHUB_NAME