-
Notifications
You must be signed in to change notification settings - Fork 0
40 lines (33 loc) · 1.29 KB
/
docker-publish.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
name: Tickets IFSP WEB - GHCR
on:
push:
branches:
- main
- homolog
jobs:
docker-build:
runs-on: ubuntu-latest
steps:
- name: Check out the repository
uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Log in to GitHub Container Registry
run: echo "${{ secrets.GHCR_TOKEN }}" | docker login ghcr.io -u "${{ github.actor }}" --password-stdin
- name: Set branch-specific tag
id: tag
run: |
if [[ "${{ github.ref_name }}" == "main" ]]; then
echo "Running on default branch 'main': tag = 'latest'"
echo "tag=latest" >> $GITHUB_ENV
else
echo "Running on branch '${{ github.ref_name }}': tag = '${{ github.ref_name }}'"
echo "tag=${{ github.ref_name }}" >> $GITHUB_ENV
fi
- name: Build and push Docker image
run: |
docker build --pull -t ghcr.io/${{ github.repository_owner }}/${{ github.repository }}:${{ env.tag }} .
docker push ghcr.io/${{ github.repository_owner }}/${{ github.repository }}:${{ env.tag }}
- name: Clean up Docker images
run: |
docker rmi ghcr.io/${{ github.repository_owner }}/${{ github.repository }}:${{ env.tag }} || true