diff --git a/.github/workflows/docker_build.yml b/.github/workflows/docker_build.yml new file mode 100644 index 000000000..63be92c2c --- /dev/null +++ b/.github/workflows/docker_build.yml @@ -0,0 +1,90 @@ +name: Docker Build Release + +on: + push: + branches: + - lightlink # Trigger the workflow on pushes to the main branch + tags: + - "**" # Trigger the workflow on tags including hierarchical tags like v1.0/beta + pull_request: + types: [opened, synchronize] # Trigger the workflow when a PR is opened or updated + +jobs: + extract-version: + name: Extract version + runs-on: ubuntu-latest + outputs: + VERSION: ${{ steps.extract_version.outputs.VERSION }} + steps: + - name: Extract version + id: extract_version + run: | + if [[ "${GITHUB_REF_TYPE}" == "tag" ]]; then + VERSION="${GITHUB_REF#refs/tags/}" + else + VERSION="$(echo ${GITHUB_SHA} | cut -c1-7)" + fi + echo "VERSION=${VERSION}" >> $GITHUB_OUTPUT + + echo "| | |" >> $GITHUB_STEP_SUMMARY + echo "| ------------------- | ---------------------- |" >> $GITHUB_STEP_SUMMARY + echo "| \`GITHUB_REF_TYPE\` | \`${GITHUB_REF_TYPE}\` |" >> $GITHUB_STEP_SUMMARY + echo "| \`GITHUB_REF_NAME\` | \`${GITHUB_REF_NAME}\` |" >> $GITHUB_STEP_SUMMARY + echo "| \`GITHUB_REF\` | \`${GITHUB_REF}\` |" >> $GITHUB_STEP_SUMMARY + echo "| \`GITHUB_SHA\` | \`${GITHUB_SHA}\` |" >> $GITHUB_STEP_SUMMARY + echo "| \`VERSION\` | \`${VERSION}\` |" >> $GITHUB_STEP_SUMMARY + + build-docker: + name: Build and publish Docker image + needs: extract-version + runs-on: ${{ matrix.configs.runner }} + env: + VERSION: ${{ needs.extract-version.outputs.VERSION }} + permissions: + contents: read + packages: write + strategy: + matrix: + configs: + - target: linux/amd64 + runner: ubuntu-latest + steps: + - name: checkout sources + uses: actions/checkout@v4 + + - name: docker qemu + uses: docker/setup-qemu-action@v3 + + - name: docker buildx + uses: docker/setup-buildx-action@v3 + + - name: docker metadata + uses: docker/metadata-action@v5 + id: meta + with: + images: ghcr.io/${{ github.repository }} + labels: org.opencontainers.image.source=${{ github.repositoryUrl }} + tags: | + type=sha + type=schedule,pattern=nightly + + - name: docker login + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: docker build and push op-rbuilder + uses: docker/build-push-action@v5 + with: + cache-from: type=gha + cache-to: type=gha,mode=max + file: Dockerfile + context: . + labels: ${{ steps.meta.outputs.labels }} + platforms: ${{ matrix.configs.target }} + push: true + tags: ${{ steps.meta.outputs.tags }} + build-args: | + RBUILDER_BIN=op-rbuilder