[WIFI-2882] Add: image build and cleanup workflow

This commit is contained in:
Dmitry Dunaev
2021-07-02 13:22:19 +03:00
parent 405e8eb944
commit 258ba197bb
2 changed files with 72 additions and 0 deletions

53
.github/workflows/build.yml vendored Normal file
View File

@@ -0,0 +1,53 @@
name: Build Docker image
on:
push:
paths-ignore:
- '**.md'
branches:
- main
pull_request:
branches:
- main
defaults:
run:
shell: bash
jobs:
docker:
runs-on: ubuntu-20.04
env:
DOCKER_REGISTRY_URL: tip-tip-wlan-cloud-ucentral.jfrog.io
DOCKER_REGISTRY_USERNAME: ucentral
steps:
- uses: actions/checkout@v2
- name: Build Docker image
run: docker build -t wlan-cloud-ucentralgw-ui:${{ github.sha }} .
- name: Log into Docker registry
uses: docker/login-action@v1
with:
registry: ${{ env.DOCKER_REGISTRY_URL }}
username: ${{ env.DOCKER_REGISTRY_USERNAME }}
password: ${{ secrets.DOCKER_REGISTRY_PASSWORD }}
- name: Push Docker image
run: |
TAGS="${{ github.sha }}"
if [ ${GITHUB_REF} == "refs/heads/main" ]
then
TAGS="$TAGS ${GITHUB_REF#refs/heads/}"
else # PR build
CURRENT_TAG=$(echo ${GITHUB_HEAD_REF#refs/heads/} | tr '/' '-')
TAGS="$TAGS $CURRENT_TAG"
fi
echo "Pushing tags $TAGS"
for tag in $TAGS; do
docker tag wlan-cloud-ucentralgw-ui:${{ github.sha }} ${{ env.DOCKER_REGISTRY_URL }}/ucentralgw-ui:$tag
docker push ${{ env.DOCKER_REGISTRY_URL }}/ucentralgw-ui:$tag
done

19
.github/workflows/cleanup.yml vendored Normal file
View File

@@ -0,0 +1,19 @@
name: Clean up PR Docker images
on:
pull_request:
branches:
- main
types: [ closed ]
defaults:
run:
shell: bash
jobs:
cleanup:
runs-on: ubuntu-latest
steps:
- run: |
export PR_BRANCH_TAG=$(echo ${GITHUB_HEAD_REF#refs/heads/} | tr '/' '-')
curl -uucentral:${{ secrets.DOCKER_REGISTRY_PASSWORD }} -X DELETE "https://tip.jfrog.io/artifactory/tip-wlan-cloud-ucentral/ucentralgw-ui/$PR_BRANCH_TAG"