-
Notifications
You must be signed in to change notification settings - Fork 62
Added Docker CI/CD #337
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Added Docker CI/CD #337
Changes from all commits
7353973
9d8a5e1
0705f0f
b33abc2
872c6fe
9d227f9
1ef5021
523eca9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.git | ||
.github | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
name: Build and Push Docker Image | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
build-and-push: | ||
runs-on: ubuntu-latest | ||
Andromeda606 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v5 | ||
Benjamin-Loison marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
- name: Allow Git safe directory | ||
run: git config --global --add safe.directory /github/workspace | ||
|
||
- name: Log in to Docker Hub | ||
uses: docker/login-action@v3 | ||
with: | ||
username: ${{ vars.DOCKER_USERNAME }} | ||
password: ${{ secrets.DOCKER_TOKEN }} | ||
|
||
- name: Set image tags | ||
id: vars | ||
run: | | ||
SHORT_SHA=$(git rev-parse --short HEAD) | ||
Benjamin-Loison marked this conversation as resolved.
Show resolved
Hide resolved
|
||
echo "COMMIT_SHA=$SHORT_SHA" >> $GITHUB_ENV | ||
echo "IMAGE_NAME=${{ vars.DOCKER_USERNAME }}/youtube-operational-api" >> $GITHUB_ENV | ||
- name: Build Docker image | ||
run: | | ||
docker build --build-arg VERSION=$COMMIT_SHA -t $IMAGE_NAME:latest -t $IMAGE_NAME:$COMMIT_SHA . | ||
- name: Push Docker image | ||
run: | | ||
docker push $IMAGE_NAME:latest | ||
docker push $IMAGE_NAME:$COMMIT_SHA | ||
Andromeda606 marked this conversation as resolved.
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
.env | ||
ytPrivate/keys.txt | ||
ytPrivate/keys.txt |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,18 @@ | ||
FROM php:apache | ||
FROM php:apache AS builder | ||
Benjamin-Loison marked this conversation as resolved.
Show resolved
Hide resolved
|
||
RUN apt-get update && apt-get install -y git protobuf-compiler | ||
COPY --from=composer/composer:latest-bin /composer /usr/bin/composer | ||
COPY . /app | ||
WORKDIR /app | ||
Andromeda606 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
RUN composer require google/protobuf \ | ||
&& protoc --php_out=proto/php/ --proto_path=proto/prototypes/ $(find proto/prototypes/ -type f) | ||
|
||
# Final image | ||
FROM php:apache | ||
RUN a2enmod rewrite | ||
|
||
# Copy application files into the container | ||
COPY . /var/www/html/ | ||
|
||
COPY --from=builder /app /var/www/html/ | ||
# Replace `AllowOverride None` with `AllowOverride All` in `<Directory /var/www/>` in `/etc/apache2/apache2.conf`. | ||
Benjamin-Loison marked this conversation as resolved.
Show resolved
Hide resolved
|
||
RUN sed -ri -e 'N;N;N;s/(<Directory \/var\/www\/>\n)(.*\n)(.*)AllowOverride None/\1\2\3AllowOverride All/;p;d;' /etc/apache2/apache2.conf | ||
|
||
COPY --from=composer/composer:latest-bin /composer /usr/bin/composer | ||
RUN apt update | ||
RUN apt install -y git protobuf-compiler | ||
RUN composer require google/protobuf | ||
RUN protoc --php_out=proto/php/ --proto_path=proto/prototypes/ $(find proto/prototypes/ -type f) | ||
|
||
CMD apachectl -D FOREGROUND | ||
ARG VERSION | ||
ENV VERSION=$VERSION | ||
EXPOSE 80 | ||
ENTRYPOINT ["apachectl", "-D", "FOREGROUND"] |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -120,25 +120,15 @@ If you want me to advertise your instance (if you have opened your port, and hav | |
|
||
## Run the API with Docker | ||
|
||
Benjamin-Loison marked this conversation as resolved.
Show resolved
Hide resolved
|
||
1. Install [Docker](https://www.docker.com) and make sure that its daemon is running. | ||
|
||
2. Create a `.env` file and update it with your preferred port: | ||
|
||
```sh | ||
cp .env.sample .env | ||
``` | ||
|
||
3. Start the container with `docker-compose`: | ||
Start the container using: | ||
|
||
```sh | ||
# start in the foreground | ||
docker-compose up | ||
# start in the background | ||
docker-compose up -d | ||
docker run -p 8080:80 benjaminloison/youtube-operational-api | ||
Benjamin-Loison marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What if the person just has the repository cloned (and appropriate dependencies and no Internet access) or does not want to use closed-source DockerHub?
Output:
Output:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In this case, they can use the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Personal note:
Output:
Output:
Output:
Output:
Output:
does not change.
Output:
Output:
works as wanted contrarily to previous command.
Output:
Output:
Output:
Output:
Related to Improve_websites_thanks_to_open_source/issues/2210. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you please specify instructions here for people willing to use Docker, but not use Docker Hub? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In fact, the change he needs to make should be manual. You must enter the host and port in the CI/CD and the person looking for the alternative can find it For example; docker push 127.0.0.1:9876/YouTube-Api I'm not sure how we can explain this in the documentation There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There seem to be 2 possibilities here related to #discussion_r2303952474:
Do you have an opinion about it? |
||
``` | ||
|
||
4. Verify that your API instance is reachable by trying to access: | ||
- http://localhost:8080 (update preferred port if not 8080) | ||
Then verify that the API is running by opening your browser or using an HTTP client: | ||
[http://localhost:80](http://localhost:80) | ||
Andromeda606 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
> Note: If you prefer a different port, adjust the -p 8080:80 option accordingly. | ||
|
||
## Contact: | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.