Skip to content

Commit afeeb60

Browse files
committed
github actions: add publish pipeline
1 parent 5fca966 commit afeeb60

File tree

1 file changed

+41
-6
lines changed

1 file changed

+41
-6
lines changed

Diff for: .github/workflows/build-test.yml renamed to .github/workflows/build-test-publish.yml

+41-6
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@ on:
44
push:
55
branches:
66
- "**"
7-
pull_request:
8-
branches: [main]
7+
98
env:
109
DOCKER_ENV_FILE: ".github/workflows/docker.env"
10+
REGISTRY: ghcr.io
11+
IMAGE_NAME: ${{ github.repository }}
12+
1113
jobs:
1214
build-test:
1315
runs-on: ubuntu-latest
1416
steps:
1517
- uses: actions/[email protected]
16-
# - name: Create k8s Kind Cluster
17-
# uses: helm/kind-action@v1
1818

1919
- name: setup@kindconfig
2020
run: |
@@ -37,10 +37,10 @@ jobs:
3737
sed "s/127.0.0.1/$hostip/g" $HOME/.kube/config > ${{ github.workspace }}/kubeconfig.yml
3838
3939
- name: Build the Docker image
40-
run: docker build --target builder --file Dockerfile --tag allaboutapps/backup-ns:${GITHUB_SHA:8} .
40+
run: docker build --target builder --file Dockerfile --tag ${IMAGE_NAME}-builder:${GITHUB_SHA:8} .
4141

4242
- name: Create container
43-
run: docker run -d --env-file $DOCKER_ENV_FILE --name=builder -it allaboutapps/backup-ns:${GITHUB_SHA:8}
43+
run: docker run -d --env-file $DOCKER_ENV_FILE --name=builder -it ${IMAGE_NAME}-builder:${GITHUB_SHA:8}
4444

4545
- name: Init Kind
4646
run: docker exec builder bash /app/test/init_kind.sh
@@ -61,3 +61,38 @@ jobs:
6161
- name: Remove container
6262
if: ${{ always() }}
6363
run: docker rm builder
64+
65+
publish:
66+
if: github.event_name == 'tag' || (github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/dev')) ||
67+
needs:
68+
- build-test
69+
runs-on: ubuntu-latest
70+
permissions:
71+
contents: read
72+
packages: write
73+
74+
steps:
75+
- uses: actions/[email protected]
76+
77+
- name: Log in to the Container registry
78+
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
79+
with:
80+
registry: ${{ env.REGISTRY }}
81+
username: ${{ github.actor }}
82+
password: ${{ secrets.GITHUB_TOKEN }}
83+
84+
- name: Extract metadata (tags, labels) for Docker
85+
id: meta
86+
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
87+
with:
88+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
89+
90+
- name: Build and push Docker image
91+
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
92+
with:
93+
context: .
94+
push: true
95+
tags: |
96+
${{ steps.meta.outputs.tags }}
97+
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.sha }}
98+
labels: ${{ steps.meta.outputs.labels }}

0 commit comments

Comments
 (0)