|
9 | 9 | jobs: |
10 | 10 | build: |
11 | 11 | runs-on: ubuntu-latest |
| 12 | + permissions: |
| 13 | + contents: read |
| 14 | + packages: write # Grant write permission to packages |
12 | 15 | steps: |
13 | 16 | - name: Checkout repository |
14 | 17 | uses: actions/checkout@v4 |
15 | 18 |
|
| 19 | + - name: Log in to GitHub Container Registry |
| 20 | + uses: docker/login-action@v3 |
| 21 | + with: |
| 22 | + registry: ghcr.io |
| 23 | + username: ${{ github.actor }} |
| 24 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 25 | + |
16 | 26 | - name: Build and tag the Docker image |
17 | 27 | run: | |
18 | | - docker build . --file Dockerfile --tag doh-server:latest |
19 | | - # If you want to push to Docker Hub, uncomment the following lines |
20 | | - # and ensure DOCKER_USERNAME and DOCKER_PASSWORD are set as GitHub Secrets. |
21 | | - # echo "${{ secrets.DOCKER_PASSWORD }}" | docker login -u "${{ secrets.DOCKER_USERNAME }}" --password-stdin |
22 | | - # docker tag doh-server:latest your_dockerhub_username/doh-server:latest |
23 | | - # docker push your_dockerhub_username/doh-server:latest |
| 28 | + IMAGE_NAME=doh-server |
| 29 | + IMAGE_TAG=${{ github.sha }} |
| 30 | + # Use lowercase for owner and repo name for GHCR compatibility |
| 31 | + REPO_OWNER=$(echo ${{ github.repository_owner }} | tr '[:upper:]' '[:lower:]') |
| 32 | + REPO_NAME=$(echo ${{ github.event.repository.name }} | tr '[:upper:]' '[:lower:]') |
| 33 | + GHCR_IMAGE=ghcr.io/$REPO_OWNER/$REPO_NAME/$IMAGE_NAME |
| 34 | +
|
| 35 | + docker build . --file Dockerfile --tag $GHCR_IMAGE:latest --tag $GHCR_IMAGE:$IMAGE_TAG |
| 36 | +
|
| 37 | + - name: Push the Docker image to GitHub Container Registry |
| 38 | + run: | |
| 39 | + IMAGE_NAME=doh-server |
| 40 | + IMAGE_TAG=${{ github.sha }} |
| 41 | + REPO_OWNER=$(echo ${{ github.repository_owner }} | tr '[:upper:]' '[:lower:]') |
| 42 | + REPO_NAME=$(echo ${{ github.event.repository.name }} | tr '[:upper:]' '[:lower:]') |
| 43 | + GHCR_IMAGE=ghcr.io/$REPO_OWNER/$REPO_NAME/$IMAGE_NAME |
| 44 | +
|
| 45 | + docker push $GHCR_IMAGE:latest |
| 46 | + docker push $GHCR_IMAGE:$IMAGE_TAG |
0 commit comments