|
| 1 | +name: Build and Push Docker Image |
| 2 | + |
| 3 | +on: [push] |
| 4 | + |
| 5 | +jobs: |
| 6 | + push_to_registry: |
| 7 | + name: Push Docker image to GitHub Packages |
| 8 | + runs-on: ubuntu-latest |
| 9 | + steps: |
| 10 | + - name: Check out the repo |
| 11 | + uses: actions/checkout@v2 |
| 12 | + |
| 13 | + - name: Lowercase repo owner |
| 14 | + id: lowercase_repo_owner |
| 15 | + uses: ASzc/change-string-case-action@v1 |
| 16 | + with: |
| 17 | + string: ${{ github.repository_owner }} |
| 18 | + |
| 19 | + - name: Prepare labels and tags |
| 20 | + id: prep |
| 21 | + run: | |
| 22 | + DOCKER_IMAGE=ghcr.io/${{ steps.lowercase_repo_owner.outputs.lowercase }}/von-network |
| 23 | + VERSION=edge |
| 24 | + if [[ $GITHUB_REF == refs/tags/* ]]; then |
| 25 | + VERSION=${GITHUB_REF#refs/tags/} |
| 26 | + elif [[ $GITHUB_REF == refs/heads/* ]]; then |
| 27 | + VERSION=$(echo ${GITHUB_REF#refs/heads/} | sed -r 's#/+#-#g') |
| 28 | + elif [[ $GITHUB_REF == refs/pull/* ]]; then |
| 29 | + VERSION=pr-${{ github.event.number }} |
| 30 | + fi |
| 31 | + TAGS="${DOCKER_IMAGE}:${VERSION}" |
| 32 | + if [ "${{ github.event_name }}" = "push" ]; then |
| 33 | + TAGS="$TAGS,${DOCKER_IMAGE}:sha-${GITHUB_SHA::8}" |
| 34 | + fi |
| 35 | + echo ::set-output name=version::${VERSION} |
| 36 | + echo ::set-output name=tags::${TAGS} |
| 37 | + echo ::set-output name=created::$(date -u +'%Y-%m-%dT%H:%M:%SZ') |
| 38 | +
|
| 39 | + - name: Log in to GitHub Container Registry |
| 40 | + uses: docker/login-action@v1 |
| 41 | + with: |
| 42 | + registry: ghcr.io |
| 43 | + username: ${{ github.actor }} |
| 44 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 45 | + |
| 46 | + - name: Set up Docker Buildx |
| 47 | + uses: docker/setup-buildx-action@v1 |
| 48 | + |
| 49 | + - name: Build and push von-network image |
| 50 | + uses: docker/build-push-action@v2 |
| 51 | + with: |
| 52 | + context: . |
| 53 | + push: ${{ github.event_name != 'pull_request' }} |
| 54 | + tags: ${{ steps.prep.outputs.tags }} |
| 55 | + labels: | |
| 56 | + org.opencontainers.image.source=${{ github.event.repository.html_url }} |
| 57 | + org.opencontainers.image.created=${{ steps.prep.outputs.created }} |
| 58 | + org.opencontainers.image.revision=${{ github.sha }} |
| 59 | +
|
0 commit comments