Skip to content

Commit 013dd67

Browse files
committed
dev: publish with container workflow
1 parent 88d7f49 commit 013dd67

File tree

2 files changed

+65
-93
lines changed

2 files changed

+65
-93
lines changed

.github/workflows/container.yaml

Lines changed: 65 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
1-
name: Container (Docker)
1+
name: Container
22

33
on:
44
push:
5+
tags-ignore:
6+
- "!v*"
57
pull_request:
8+
branches:
9+
- "develop"
10+
- "main"
611

712
env:
813
CARGO_TERM_COLOR: always
914

1015
jobs:
1116
test:
12-
name: Test
17+
name: Test (Docker)
1318
runs-on: ubuntu-latest
1419

1520
steps:
16-
- id: checkout
17-
name: Checkout Repository
18-
uses: actions/checkout@v3
19-
2021
- id: setup
2122
name: Setup Toolchain
2223
uses: docker/setup-buildx-action@v2
@@ -25,7 +26,6 @@ jobs:
2526
name: Build
2627
uses: docker/build-push-action@v4
2728
with:
28-
context: .
2929
file: ./Containerfile
3030
push: false
3131
load: true
@@ -40,3 +40,61 @@ jobs:
4040
- id: compose
4141
name: Compose
4242
run: docker compose build
43+
44+
check-secret:
45+
name: Check Secrets
46+
needs: test
47+
environment: dockerhub-torrust
48+
runs-on: ubuntu-latest
49+
50+
outputs:
51+
publish: ${{ steps.docker_hub.outputs.publish }}
52+
53+
steps:
54+
- id: docker_hub
55+
name: Docker Hub
56+
env:
57+
DOCKER_HUB_ACCESS_TOKEN: "${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}"
58+
if: "${{ env.DOCKER_HUB_ACCESS_TOKEN != '' }}"
59+
run: echo "publish=true" >> $GITHUB_OUTPUT
60+
61+
publish:
62+
name: Publish
63+
environment: dockerhub-torrust
64+
needs: check-secret
65+
if: needs.check-secret.outputs.publish == 'true'
66+
runs-on: ubuntu-latest
67+
68+
steps:
69+
- id: meta
70+
name: Docker meta
71+
uses: docker/metadata-action@v4
72+
with:
73+
images: |
74+
"${{ secrets.DOCKER_HUB_USERNAME }}/${{secrets.DOCKER_HUB_REPOSITORY_NAME }}"
75+
tags: |
76+
type=ref,event=branch
77+
type=ref,event=pr
78+
type=semver,pattern={{version}}
79+
type=semver,pattern={{major}}.{{minor}}
80+
81+
- id: login
82+
name: Login to Docker Hub
83+
uses: docker/login-action@v2
84+
with:
85+
username: ${{ secrets.DOCKER_HUB_USERNAME }}
86+
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
87+
88+
- id: setup
89+
name: Setup Toolchain
90+
uses: docker/setup-buildx-action@v2
91+
92+
- name: Build and push
93+
uses: docker/build-push-action@v4
94+
with:
95+
file: ./Containerfile
96+
push: ${{ github.event_name != 'pull_request' }}
97+
tags: ${{ steps.meta.outputs.tags }}
98+
labels: ${{ steps.meta.outputs.labels }}
99+
cache-from: type=gha
100+
cache-to: type=gha,mode=max

.github/workflows/publish_docker_image.yml

Lines changed: 0 additions & 86 deletions
This file was deleted.

0 commit comments

Comments
 (0)