Skip to content

Commit a2dbc84

Browse files
committed
Fixed #3
1 parent 4e68a98 commit a2dbc84

3 files changed

Lines changed: 139 additions & 0 deletions

File tree

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
name: Build and Push Docker Image
2+
3+
on:
4+
push:
5+
branches: [ master, main, develop ]
6+
pull_request:
7+
branches: [ master, main, develop ]
8+
workflow_dispatch: # Allow manual triggering
9+
10+
env:
11+
DOCKER_IMAGE: webcuisine/gitlab-ci-react-native-android
12+
TAG_VERSION: android-28.0.3
13+
14+
jobs:
15+
build-and-push:
16+
runs-on: ubuntu-latest
17+
18+
steps:
19+
- name: Checkout repository
20+
uses: actions/checkout@v4
21+
22+
- name: Set up Docker Buildx
23+
uses: docker/setup-buildx-action@v3
24+
25+
- name: Log in to Docker Hub
26+
if: github.event_name != 'pull_request'
27+
uses: docker/login-action@v3
28+
with:
29+
username: ${{ secrets.DOCKER_USERNAME }}
30+
password: ${{ secrets.DOCKER_PASSWORD }}
31+
32+
- name: Extract metadata
33+
id: meta
34+
uses: docker/metadata-action@v5
35+
with:
36+
images: ${{ env.DOCKER_IMAGE }}
37+
tags: |
38+
type=ref,event=branch
39+
type=ref,event=pr
40+
type=raw,value=latest,enable={{is_default_branch}}
41+
type=raw,value=${{ env.TAG_VERSION }}
42+
43+
- name: Build and push Docker image
44+
uses: docker/build-push-action@v5
45+
with:
46+
context: .
47+
file: ./Dockerfile
48+
push: ${{ github.event_name != 'pull_request' }}
49+
tags: ${{ steps.meta.outputs.tags }}
50+
labels: ${{ steps.meta.outputs.labels }}
51+
cache-from: type=gha
52+
cache-to: type=gha,mode=max
53+
54+
- name: Update Docker Hub description
55+
if: github.event_name != 'pull_request' && github.ref == 'refs/heads/develop'
56+
uses: peter-evans/dockerhub-description@v3
57+
with:
58+
username: ${{ secrets.DOCKER_USERNAME }}
59+
password: ${{ secrets.DOCKER_PASSWORD }}
60+
repository: ${{ env.DOCKER_IMAGE }}
61+
readme-filepath: ./README.md

GITHUB_ACTIONS_SETUP.md

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# GitHub Actions Setup for Docker Hub Publishing
2+
3+
This repository uses GitHub Actions to automatically build and push the Docker image to Docker Hub whenever changes are made to the repository.
4+
5+
## Setup Instructions
6+
7+
### 1. Configure Docker Hub Secrets
8+
9+
You need to add the following secrets to your GitHub repository:
10+
11+
1. Go to your repository on GitHub
12+
2. Navigate to **Settings****Secrets and variables****Actions**
13+
3. Add the following repository secrets:
14+
15+
- `DOCKER_USERNAME`: Your Docker Hub username
16+
- `DOCKER_PASSWORD`: Your Docker Hub access token (see below for 2FA setup)
17+
18+
#### For Docker Hub accounts with 2FA enabled:
19+
20+
Since your Docker Hub account uses 2FA, you **must** use an access token instead of your password:
21+
22+
1. **Create a Docker Hub Access Token**:
23+
- Log in to [Docker Hub](https://hub.docker.com/)
24+
- Go to **Account Settings****Security**
25+
- Click **New Access Token**
26+
- Choose a descriptive name (e.g., "GitHub Actions CI")
27+
- Select permissions: **Read, Write, Delete** (for pushing images)
28+
- Click **Generate**
29+
- **Important**: Copy the token immediately as it won't be shown again
30+
31+
2. **Add the token to GitHub Secrets**:
32+
- Use the generated access token as the value for `DOCKER_PASSWORD`
33+
- Do **NOT** use your actual Docker Hub password
34+
35+
### 2. Workflow Triggers
36+
37+
The workflow is configured to run:
38+
- On pushes to `master`, `main`, or `develop` branches
39+
- On pull requests to `master`, `main`, or `develop` branches (build only, no push)
40+
- Manually via the GitHub Actions interface
41+
42+
### 3. Tags and Versions
43+
44+
The workflow will automatically create the following tags:
45+
- `latest` (only for the default branch)
46+
- `android-28.0.3` (version tag)
47+
- Branch-specific tags for development
48+
49+
### 4. Manual Trigger
50+
51+
You can manually trigger the workflow:
52+
1. Go to **Actions** tab in your repository
53+
2. Select "Build and Push Docker Image"
54+
3. Click "Run workflow"
55+
4. Choose the branch and click "Run workflow"
56+
57+
## Docker Hub Integration
58+
59+
The workflow also updates the Docker Hub repository description with the README.md content from this repository, keeping the documentation synchronized.
60+
61+
## Troubleshooting
62+
63+
- Ensure Docker Hub credentials are correctly set in repository secrets
64+
- Check that the Docker Hub repository exists and you have push permissions
65+
- Verify the workflow has the necessary permissions to access secrets
66+
67+
## Fix for Issue #3
68+
69+
This GitHub Actions workflow resolves [Issue #3](https://github.com/cuisines/gitlab-ci-react-native-android/issues/3) by automatically keeping the Docker Hub image in sync with the repository changes.

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,15 @@ build:
2828
```
2929
or like this [example with fastlane](./exampleWithFastlane.md)
3030

31+
## Automated Docker Hub Publishing
32+
33+
This repository uses GitHub Actions to automatically build and push the Docker image to Docker Hub whenever changes are made. The image is available at:
34+
35+
- **Latest**: `webcuisine/gitlab-ci-react-native-android:latest`
36+
- **Versioned**: `webcuisine/gitlab-ci-react-native-android:android-28.0.3`
37+
38+
See [GITHUB_ACTIONS_SETUP.md](./GITHUB_ACTIONS_SETUP.md) for setup instructions.
39+
3140
## Detached testing
3241
Build locally
3342
```

0 commit comments

Comments
 (0)