|
| 1 | +name: Build and Push to GHCR |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + #branches: |
| 6 | + # - master |
| 7 | + |
| 8 | + # Publish semver tags as releases. |
| 9 | + tags: [ 'v*.*.*' ] |
| 10 | + pull_request: |
| 11 | + branches: [ "master" ] |
| 12 | + |
| 13 | +env: |
| 14 | + # Use docker.io for Docker Hub if empty |
| 15 | + REGISTRY: ghcr.io |
| 16 | + # github.repository as <account>/<repo> |
| 17 | + IMAGE_NAME: ${{ github.repository }} |
| 18 | + ORG_NAME: league-infrastructure |
| 19 | + |
| 20 | +jobs: |
| 21 | + build-and-push: |
| 22 | + runs-on: ubuntu-latest |
| 23 | + permissions: |
| 24 | + contents: read |
| 25 | + packages: write |
| 26 | + attestations: write |
| 27 | + id-token: write |
| 28 | + |
| 29 | + steps: |
| 30 | + # Step 1: Check out the repository |
| 31 | + - name: Checkout code |
| 32 | + uses: actions/checkout@v3 |
| 33 | + |
| 34 | + # Step 2: Install devcontainers CLI |
| 35 | + - name: Install devcontainers CLI |
| 36 | + run: npm install -g @devcontainers/cli |
| 37 | + |
| 38 | + # Step 3: Log in to GitHub Container Registry |
| 39 | + - name: Log in to GitHub Container Registry |
| 40 | + uses: docker/login-action@v2 |
| 41 | + with: |
| 42 | + registry: ghcr.io |
| 43 | + username: ${{ github.actor }} |
| 44 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 45 | + |
| 46 | + - name: Set Image Tag |
| 47 | + id: image_tag |
| 48 | + run: | |
| 49 | + TAG=$(echo "${GITHUB_REF}" | sed 's|refs/tags/||') |
| 50 | + echo "TAG=${TAG}" >> $GITHUB_ENV |
| 51 | + echo "LATEST_TAG=true" >> $GITHUB_ENV |
| 52 | + shell: bash |
| 53 | + |
| 54 | + # Step 4: Build the Dev Container image |
| 55 | + - name: Build Dev Container image |
| 56 | + run: | |
| 57 | + devcontainer build --workspace-folder . --image-name ${{ env.REGISTRY }}/${{ env.ORG_NAME }}/${{ env.IMAGE_NAME }}:${{ env.TAG }} |
| 58 | +
|
| 59 | + # Step 5: Tag image as latest |
| 60 | + - name: Tag image as latest |
| 61 | + run: | |
| 62 | + docker tag ${{ env.REGISTRY }}/${{ env.ORG_NAME }}/${{ env.IMAGE_NAME }}:${{ env.TAG }} \ |
| 63 | + ${{ env.REGISTRY }}/${{ env.ORG_NAME }}/${{ env.IMAGE_NAME }}:latest |
| 64 | +
|
| 65 | + # Step 6: Push Docker image |
| 66 | + - name: Push Docker image |
| 67 | + run: | |
| 68 | + docker push ${{ env.REGISTRY }}/${{ env.ORG_NAME }}/${{ env.IMAGE_NAME }}:${{ env.TAG }} |
| 69 | + docker push ${{ env.REGISTRY }}/${{ env.ORG_NAME }}/${{ env.IMAGE_NAME }}:latest |
0 commit comments