Build image #7
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: "Build image" | |
| on: | |
| schedule: | |
| - cron: "0 1 7 * *" | |
| workflow_dispatch: | |
| permissions: | |
| contents: read | |
| packages: write | |
| jobs: | |
| date: | |
| name: Get current date in RFC 3339 | |
| runs-on: ubuntu-latest | |
| outputs: | |
| date: ${{ steps.date.outputs.date }} | |
| steps: | |
| - name: Get current date in RFC 3339 | |
| id: date | |
| run: | | |
| echo "date=$(date --rfc-3339=seconds | sed 's/ /T/')" >> $GITHUB_OUTPUT | |
| version: | |
| name: Get latest package version | |
| runs-on: ubuntu-latest | |
| outputs: | |
| package_version: ${{ steps.version.outputs.package_version }} | |
| steps: | |
| - name: Add Microsoft's APT repo for VS Code | |
| run: | | |
| sudo curl -vSLo \ | |
| /etc/apt/keyrings/packages.microsoft.asc \ | |
| https://packages.microsoft.com/keys/microsoft.asc | |
| echo \ | |
| "deb [signed-by=/etc/apt/keyrings/packages.microsoft.asc] https://packages.microsoft.com/repos/code stable main" \ | |
| | sudo tee -a /etc/apt/sources.list.d/microsoft.list | |
| sudo apt-get update -y | |
| - name: Get package version | |
| id: version | |
| run: | | |
| package_version=$(apt list code 2>/dev/null | grep -v "^Listing" | awk '{print $2}' | cut -d'-' -f1) | |
| echo "package_version=${package_version}" >> $GITHUB_OUTPUT | |
| echo "The package version is $package_version" | |
| build: | |
| name: Build and push image | |
| runs-on: ubuntu-latest | |
| needs: [date, version] | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Login to GitHub Container Registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.repository_owner }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Login to Docker Hub | |
| uses: docker/login-action@v3 | |
| with: | |
| username: ${{ vars.DOCKERHUB_USERNAME }} | |
| password: ${{ secrets.DOCKERHUB_TOKEN }} | |
| - name: Set up QEMU | |
| uses: docker/setup-qemu-action@v3 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Build and push image for amd64/arm64 | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: . | |
| platforms: linux/amd64,linux/arm64 | |
| file: ./Dockerfile | |
| push: true | |
| build-args: | | |
| IMAGE_BUILD_DATE=${{ needs.date.outputs.date }} | |
| tags: | | |
| ghcr.io/${{ github.repository_owner }}/code-tunnel:latest | |
| ghcr.io/${{ github.repository_owner }}/code-tunnel:${{ needs.version.outputs.package_version }} | |
| ${{ vars.DOCKERHUB_USERNAME }}/code-tunnel:latest | |
| ${{ vars.DOCKERHUB_USERNAME }}/code-tunnel:${{ needs.version.outputs.package_version }} | |
| labels: | | |
| org.opencontainers.image.ref.name=${{ github.ref }} | |
| org.opencontainers.image.revision=${{ github.sha }} | |
| org.opencontainers.image.version=${{ needs.version.outputs.package_version }} |