Skip to content

Commit

Permalink
feature: push and pull from dockerhub
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgeav527 committed Jun 5, 2024
1 parent 3d8982c commit dcedae0
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 6 deletions.
60 changes: 60 additions & 0 deletions .github/workflows/staging.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: CI/CD to staging

on:
push:
branches:
- main

jobs:
CI:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Set up Docker environment
run: |
echo "DOCKER_BUILDKIT=1" >> $GITHUB_ENV
echo "COMPOSE_DOCKER_CLI_BUILD=1" >> $GITHUB_ENV
- name: Build and push with Docker Compose
run: |
docker compose -f docker-compose.yml build rest-api
docker compose -f docker-compose.yml push rest-api
CD:
needs: CI
runs-on:
- self-hosted
- staging

steps:
- name: Checkout the latest code
uses: actions/checkout@v3

- name: Docker Hub login
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Pull the Docker image
run: |
cd $GITHUB_WORKSPACE
docker compose -f docker-compose.yml pull
- name: Start the container
run: |
cd $GITHUB_WORKSPACE
docker compose -f docker-compose.yml up -d
- name: Remove old Docker images
run: |
docker rmi $(docker images devroadr/python-api-server -f "dangling=true" -q) || true
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
################################################################################
# Create a stage for building the application.

ARG RUST_VERSION=1.70.0
ARG RUST_VERSION=1.76.0
ARG APP_NAME=cdci_rust
FROM rust:${RUST_VERSION}-slim-bullseye AS build
ARG APP_NAME
Expand Down Expand Up @@ -61,7 +61,7 @@ USER appuser
COPY --from=build /bin/server /bin/

# Expose the port that the application listens on.
EXPOSE 8000
EXPOSE 8080

# What the container should run when it is started.
CMD ["/bin/server"]
6 changes: 3 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
services:
api:
image: jorgeav527/api-rust
rest-api:
image: devroadr/cdci_rust
build:
context: .
dockerfile: Dockerfile
target: final
ports:
- "8000:8000"
- "8080:8080"
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ async fn main() -> std::io::Result<()> {
.service(echo)
.route("/hey", web::get().to(manual_hello))
})
.bind(("127.0.0.1", 8000))?
.bind(("0.0.0.0", 8080))?
.run()
.await
}

0 comments on commit dcedae0

Please sign in to comment.