I want to deploy to an enviroment using a docker image, but using the .yml below the process gets 'stuck' because of the run command, which supposed to run the docker container, how can I make sure the action ends but the enviroment 'staging' runs the container?
on:
push:
branches: [ master ]
jobs:
staging:
# The type of runner that the job will run on
runs-on: ubuntu-latest
environment:
name: staging
url: https://website.com
env:
DOCKERHUB_REPOSITORY: ${{ secrets.DOCKERHUB_REPOSITORY }}
DOCKERHUB_REPOSITORY_FULL: ${{ secrets.DOCKERHUB_REPOSITORY_FULL }}
steps:
- uses: actions/checkout#v2
- name: docker login
env:
DOCKERHUB_USER: ${{ secrets.DOCKERHUB_USER }}
DOCKERHUB_ACCESS_TOKEN: ${{ secrets.DOCKERHUB_ACCESS_TOKEN }}
run: |
docker login -u $DOCKERHUB_USER -p $DOCKERHUB_ACCESS_TOKEN
- name: docker build
run: |
docker build -t $DOCKERHUB_REPOSITORY .
docker tag $DOCKERHUB_REPOSITORY $DOCKERHUB_REPOSITORY_FULL
- name: docker push
run: |
docker push $DOCKERHUB_REPOSITORY_FULL
- name: docker run
run: |
docker run --network="host" $DOCKERHUB_REPOSITORY
I tried removing the run command alltogether from the .yml but that's just made the .yml to run successfully but without a running enviroment.
Related
I've developed a set of tests, which to run locally, all I need to do is to launch an Elasticsearch docker container, by going to the folder with the docker-compose.yml file, and on the bash do docker compose up -d. Then, I run the script with the tests.
I want to create a specific github workflow with these tests.
How would one go about it? I'm a complete novice when it comes to github.
Any help would be appreciated.
Here's my starting point(I haven't run it, because it's very likely not to run without errors)
name: local_db_testing
run-name: ${{ github.actor }} is testing on local ES db
on:
pull_request:
branches: [main, dev,ci_testing_branch]
types: [opened, reopened]
push:
paths-ignore:
- '**.md'
- './docs'
- 'Dockerfile'
jobs:
run_tests:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.8]
steps:
- name: Setup Python
uses: actions/setup-python#v4
with:
python-version: ${{ matrix.python-version }}
- name: Checkout branch
uses: actions/checkout#v3
- name: Install requirements
run: |
pip install -r requirements.txt
- name: Launching ES db container
run: |
cd ./elasticsearch_local_db
run docker compose up -d
- name: Execute tests
run: |
cd ./tests/local_ES_tests
python -m pytest test_set.py
I would like to deploy my application with a CI CD pipeline. I used appleboy/ssh-action#master and github actions. I generated an ssh key pair in git bash and I added the the pub file to my profile and the private key to secrets in the repo. The problem is that I don't know the hostname and the port number but I need it to deploy. Can somebody help me? I don't have any experience with this.
This is my github actions yaml file:
name: Deploy application
on:
push:
branches: [master]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: multiple command
uses: appleboy/ssh-action#master
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USER }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
port: ${{ secrets.SSH_PORT }}
script: |
docker system prune -a -f
cd /mnt/tourmix-main
git clean -ffdx
git pull origin master --rebase
make release
docker system prune -a -f
guys!
I need you help to run docker-compose build on github action. I have a docker-compose file and I can't understand how to build and deploy it in correct way besides of just copying docker-compose by ssh and run scripts there.
There's docker/build-push-action#v2 but it's not working with docker-compose.yml.
This strongly depends where do you want to push your images. But for instance if you use Azure ACR you can use this action
on: [push]
name: AzureCLISample
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- name: Azure Login
uses: azure/login#v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
- name: Azure CLI script
uses: azure/CLI#v1
with:
azcliversion: 2.0.72
inlineScript: |
az acr login --name <acrName>
docker-compose up
docker-compose push
And then just build and push your images. But this is an example. If you use ECR it would be similar I guess.
For DigitialOcean it would be like this:
steps:
- uses: actions/checkout#v2
- name: Build image
run: docker-compose up
- name: Install doctl # install the doctl on the runner
uses: digitalocean/action-doctl#v2
with:
token: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }}
- name: push image to digitalocean
run: |
doctl registry login
docker-compose push
You can find more details about this here
Here is my workflow file:
name: Integration
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- name: run docker-build with tag
run: ./docker-build sudipbhandari/springboot-docker-app:$GITHUB_SHA
- name: list docker images
run: docker image ls
- name: Docker Login
uses: Azure/docker-login#v1
with:
login-server: 'docker.io'
username: '{{secrets.DOCKER_HUB_USERNAME}}'
password: '{{secrets.DOCKER_HUB_PASSWORD}}'
- name : docker push
run: docker push sudipbhandari/springboot-docker-app:$GITHUB_SHA
- name: clean up
run: rm ~/.docker/config.json
Image:
***/springboot-docker-app 8d0caac294f0e414b88cfe6cc433995ef7ca2f25
Docker push output:
Run docker push ***/springboot-docker-app:$GITHUB_SHA
[6](https://github.com/sudipbhandari126/springboot-docker-app/runs/477583287#step:6:6)The push refers to repository [docker.io/***/springboot-docker-app]
[7](https://github.com/sudipbhandari126/springboot-docker-app/runs/477583287#step:6:7)945b12e86d4e: Preparing
[8](https://github.com/sudipbhandari126/springboot-docker-app/runs/477583287#step:6:8)fff0debc90b1: Preparing
[9](https://github.com/sudipbhandari126/springboot-docker-app/runs/477583287#step:6:9)ceaf9e1ebef5: Preparing
[10](https://github.com/sudipbhandari126/springboot-docker-app/runs/477583287#step:6:10)9b9b7f3d56a0: Preparing
[11](https://github.com/sudipbhandari126/springboot-docker-app/runs/477583287#step:6:11)f1b5933fe4b5: Preparing
[12](https://github.com/sudipbhandari126/springboot-docker-app/runs/477583287#step:6:12)denied: requested access to the resource is denied
Image is properly tagged (username/imagename:tag)
Docker login is successful to registry (docker.io)
Still I am gettting permission denied.
I locally built and tried to push the image and it works just fine.
docker push sudipbhandari/springboot-docker-app:a
The push refers to repository [docker.io/sudipbhandari/springboot-docker-app]
f2f6c53c3c45: Layer already exists
9ff7271739b8: Layer already exists
ceaf9e1ebef5: Layer already exists
9b9b7f3d56a0: Layer already exists
f1b5933fe4b5: Layer already exists
a: digest: sha256:ecf90929be9690c052bcc457edd5bb12cbe231029b63536d94e0e86cd845b983 size: 1366
First, in GitHub go to Setting>Secrets and add two repository secrets for DOCKER_USERNAME and DOCKER_PASSWORD. Then try this:
- run:
echo ${{ secrets.DOCKER_PASSWORD }} | docker login -u ${{ secrets.DOCKER_USERNAME }} --password-stdin
env:
$DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
$DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
I have this code at .github/workflows/main.yaml
# .github/workflows/main.yaml
name: CI Workflow
on: [push]
jobs:
rspec-job:
runs-on: ubuntu-latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
container:
image: I-stucked-here
volumes:
- /vendor/bundle
steps:
- code omitted for brevity
The main idea of this job is to run all steps in container mode. Not in Linux host mode.
Under the same repository, I have a public Docker image named ruby-rimy-2.6.3. Since it's not publicly hosted on DockerHub, I can't find a way to programmatically authenticate myself to GitHub Packages/Registry.
I did try with different syntax (see code below) but it didn't work.
# .github/workflows/main.yaml
name: CI Workflow
on: [push]
jobs:
rspec-job:
runs-on: ubuntu-latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
container:
image: docker://docker.pkg.github.com/zulhfreelancer/rimy/ruby-rimy-2.6.3:latest
volumes:
- /vendor/bundle
steps:
- code omitted for brevity
From the docs, GitHub says the GITHUB_TOKEN is available when the job is running. How do I use this GITHUB_TOKEN environment variable to run something like docker login on top of that
container: section so that the job is able to pull the image?
Using GitHub Personal Token is not an option for me because that repository is just my experiment repository before applying the same thing to my GitHub organization. I don't want to put my personal token under my organization's repository environment variables/secrets — that will simply exposes my personal token to my co-workers.
You do not need to use the container instruction to run tests in a container.
The GitHub Actions host comes with docker and docker-compose installed. The way I do it, is have a docker-compose.yml in my repository, which includes a "service" that runs tests. Then, your workflow needs to do docker login and simply run the docker-compose run test command.
Note that the beauty of this approach, is that your tests are executed exactly the same on your own machine and on the CI machine. Same exact steps.
Something along these lines:
name: Test
on:
pull_request:
push: { branches: master }
jobs:
test:
name: Run test suite
runs-on: ubuntu-latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: Checkout code
uses: actions/checkout#v2
- name: Docker login
run: echo ${GITHUB_TOKEN} | docker login -u ${GITHUB_ACTOR} --password-stdin docker.pkg.github.com
- name: Build docker images
run: docker-compose build
- name: Run tests
run: docker-compose run test
I am doing the same with DockerHub, with great ease and success.
Of course, if you do not want to use docker-compose, you can still use any normal docker run ... commands after you login properly in the login step.
I am not sure that docker login command will work as is, see these for a deeper discussion:
https://github.com/actions/starter-workflows/issues/66
https://github.community/t5/GitHub-Actions/Github-Actions-Docker-login/td-p/29852/page/2