forked from madslundt/docker-cloud-media-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
96 lines (95 loc) · 3.4 KB
/
deploy.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
name: Deploy
on:
push:
jobs:
build:
runs-on: ubuntu-latest
name: Build
steps:
- uses: actions/checkout@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
with:
install: true
- name: Build
run: |
docker build \
--tag ci:${{ github.run_number }} \
--progress plain \
--file ./Dockerfile \
--load \
.
- name: Save tarball
run: |
docker save --output output.tar ci:${{ github.run_number }}
- name: Upload Artifact
uses: actions/upload-artifact@v2
with:
name: ci-${{ github.run_number }}.tar
path: output.tar
deploy:
runs-on: ubuntu-latest
needs: [build]
name: Deploy
strategy:
matrix:
registry:
- {
url: "https://index.docker.io/v1/",
username: dockerID,
password: dockerPassword,
repo: yaoa/cloud-media-scripts
}
- {
url: ghcr.io/alexyao2015,
username: CR_USER,
password: CR_PAT,
repo: ghcr.io/alexyao2015/cloud-media-scripts/core
}
steps:
- name: Download container artifact
uses: actions/download-artifact@v2
with:
name: ci-${{ github.run_number }}.tar
- name: Set Docker Repository & Load Image
run: |
docker load --input output.tar
export DOCKER_REPO=${{ matrix.registry.repo }}
export DOCKER_IMAGE_NAME=ci:${{ github.run_number }}
echo "DOCKER_REPO=${DOCKER_REPO}" >> $GITHUB_ENV
echo "DOCKER_IMAGE_NAME=${DOCKER_IMAGE_NAME}" >> $GITHUB_ENV
echo Repository set as: ${DOCKER_REPO}
echo Image set as: ${DOCKER_IMAGE_NAME}
- name: Login
run: |
docker login ${{ matrix.registry.url }} -u ${{ secrets[matrix.registry.username] }} -p ${{ secrets[matrix.registry.password] }}
- name: Deploy Commit ID
if: ${{ github.head_ref == '' && github.sha != '' }}
run: |
docker tag ${DOCKER_IMAGE_NAME} ${DOCKER_REPO}:$GITHUB_SHA
docker push ${DOCKER_REPO}:$GITHUB_SHA
- name: Deploy Run Number
if: ${{ github.head_ref == '' && github.sha != '' }}
run: |
docker tag ${DOCKER_IMAGE_NAME} ${DOCKER_REPO}:$GITHUB_RUN_NUMBER
docker push ${DOCKER_REPO}:$GITHUB_RUN_NUMBER
- name: Deploy Latest
if: ${{ github.head_ref == '' && github.ref == 'refs/heads/master' }}
run: |
docker tag ${DOCKER_IMAGE_NAME} ${DOCKER_REPO}:latest
docker push ${DOCKER_REPO}:latest
- name: Deploy Develop
if: ${{ github.head_ref == '' && startsWith(github.ref, 'refs/heads/dev') }}
run: |
docker tag ${DOCKER_IMAGE_NAME} ${DOCKER_REPO}:latest-develop
docker push ${DOCKER_REPO}:latest-develop
- name: Deploy Branch
if: ${{ github.head_ref == '' && startsWith(github.ref, 'refs/heads/') }}
run: |
docker tag ${DOCKER_IMAGE_NAME} ${DOCKER_REPO}:${GITHUB_REF##*/}
docker push ${DOCKER_REPO}:${GITHUB_REF##*/}
- name: Deploy Tag
if: ${{ github.head_ref == '' && startsWith(github.ref, 'refs/tags/') }}
run: |
docker tag ${DOCKER_IMAGE_NAME} ${DOCKER_REPO}:${GITHUB_REF##*/}
docker push ${DOCKER_REPO}:${GITHUB_REF##*/}