forked from torrust/torrust-index
-
Notifications
You must be signed in to change notification settings - Fork 0
85 lines (76 loc) · 2.3 KB
/
publish_docker_image.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
76
77
78
79
80
81
82
83
84
85
name: Publish Docker Image
on:
push:
branches:
- "main"
- "develop"
tags:
- "v*"
env:
TORRUST_IDX_BACK_RUN_AS_USER: appuser
jobs:
check-secret:
runs-on: ubuntu-latest
environment: dockerhub-torrust
outputs:
publish: ${{ steps.check.outputs.publish }}
steps:
- id: check
env:
DOCKER_HUB_USERNAME: "${{ secrets.DOCKER_HUB_USERNAME }}"
if: "${{ env.DOCKER_HUB_USERNAME != '' }}"
run: echo "publish=true" >> $GITHUB_OUTPUT
test:
needs: check-secret
if: needs.check-secret.outputs.publish == 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@stable
with:
toolchain: stable
components: llvm-tools-preview
- uses: Swatinem/rust-cache@v2
- name: Install torrent edition tool (needed for testing)
run: cargo install imdl
- name: Run Tests
run: cargo test
dockerhub:
needs: test
if: needs.check-secret.outputs.publish == 'true'
runs-on: ubuntu-latest
environment: dockerhub-torrust
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Docker meta
id: meta
uses: docker/metadata-action@v4
with:
images: |
# For example: torrust/index
"${{ secrets.DOCKER_HUB_USERNAME }}/${{secrets.DOCKER_HUB_REPOSITORY_NAME }}"
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Build and push
uses: docker/build-push-action@v4
with:
context: .
file: ./Dockerfile
build-args: |
RUN_AS_USER=${{ env.TORRUST_IDX_BACK_RUN_AS_USER }}
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max